PDA

View Full Version : Awk



Ullrich
13th January 2007, 07:44 PM
I am running FC5.
I have a text file called 'text2'. It is purely some English text. Why did the following command failed?

[root@c83-250-99-43 Shell Scripting]# awk ' '{print $1}' text2
>

--------------------------------------------------------
I thought 'awk' was not installed on my system. I tried the following:

[root@c83-250-99-43 Nissanka]# yum install awk
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
livna [1/4]
livna 100% |=========================| 951 B 00:00
core [2/4]
core 100% |=========================| 1.1 kB 00:00
updates [3/4]
updates 100% |=========================| 1.2 kB 00:00
extras [4/4]
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 130 kB 00:00
livna : ################################################## 309/309
Added 6 new packages, deleted 4 old in 0.69 seconds
primary.xml.gz 100% |=========================| 417 kB 00:01
updates : ################################################## 1188/1188
Added 31 new packages, deleted 21 old in 2.48 seconds
primary.xml.gz 100% |=========================| 1.8 MB 00:18
extras : ################################################## 5962/5962
Added 577 new packages, deleted 397 old in 8.38 seconds
Parsing package install arguments
No Match for argument: awk
Nothing to do

homey
13th January 2007, 08:07 PM
awk ' '{print $1}' text2
>
When ever I see a > show up on the next line, I go looking for an unmatched single or double quote. In your case the extra one is right after awk.

Ullrich
13th January 2007, 08:21 PM
Thanks homey.
I can't fathom out your answer.
Anyway, please look at the following:

ls files_list | awk '{print "mv "$1" "$1".new"}' | sh
[ I guess the above command append the file ' .new' to ' file_list'.]

ls -1 *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh
[ Does this rename the file 'old' to 'new' ?]

homey
13th January 2007, 08:42 PM
Yes for both your samples.