Wednesday, January 9, 2013

Touch & More


Touch

touch [-acm] [-f agefile] [-r agefile] [[-t] time] file ...

touch [-acm] time file ...
DESCRIPTION

The touch command changes certain dates for each file argument. By default, touch sets both the date of last file modification and the date of last file access to the current time. This is useful for maintaining correct release times for software and is particularly useful in conjunction with the MKS Make software development facility.
Options

-a    sets only the access time.
-c    does not create any files that do not already exist. Normally, touch creates such files.
-m    sets only the modification time.
If you do not specify -a or -m, touch behaves as though you specified both.

To tell touch to use a time other than the current, use one of the following options:

-f agefile    is an obsolete version of the POSIX-compliant -r option.
-r agefile    sets the access and modification times (as indicated by the other options) to     those kept for agefile.
-t time     specifies a particular time using this format:

[[[[cc]yy]MM]dd]hhmm[.ss]

where cc is the optional first 2 digits of the year, yy is the optional last 2 digits of the year, MM is the optional number of the month (01-12), dd is the optional day of the month, hh is the hour in 24 hour format (required), mm is the minutes (required), ss is the optional seconds.

EXAMPLES

touch newfile

sets the modification time of newfile to the present.

touch -t 8001031305 oldfile

sets the modification time of oldfile to 13:05 on January 3, 1980.

touch -r oldfile newfile

sets the modification time of newfile to that of oldfile.

More

More is a command used to read text files. For example, we could do this:

% more poems

The effect of this to let you read the file "poems ". It probably will not fit in one screen, so you need to know how to "turn pages". Here are the basic commands:

q --- quit more
spacebar --- read next page
return key --- read next line
b --- go back one page

For still more information, use the command man more.
To display the file named letter.txt on the screen, the user can type either of the following two commands:

more < letter.txt
type letter.txt | more

The command displays the first screen of information from letter.txt, and then the following prompt appears:

-- More --

When the spacebar is pressed, the next screen of information will be displayed. It is also possible to clear the screen and remove all extra blank lines before displaying the file:

more /c /s < letter.txt
type letter.txt | more /c /s


How to concatenate two files line by line 

I have two text files; each of them contains information by line such like that
file1.txt            file2.txt
----------           ---------
linef11              linef21
linef12              linef22
linef13              linef23

I would like to concatenate theses files lines by lines using a bash script in order to obtain:
fileresult.txt
--------------
linef11     linef21
linef12     linef22
linef13     linef23

1.      paste file1.txt file2.txt > fileresults.txt

2.      awk '
  # store the first file, indexed by col2
  NR==FNR {f1[$2] = $0; next}
  # output only if file1 contains file2's col2
  ($2 in f1) {print f1[$2], $0}
' file1 file2

3.      You can do that with a combination of the sort and join commands. The straightforward approach is
join -j2 <(sort -k2 file1) <(sort -k2 file2)
But that displays slightly differently than you're looking for. It just shows the common join field and then the remaining fields from each file