Questions -
1. In there , the magic is happening all because of $0=$2. Can someone please explain to me as to what does $0=$2 means ?
2. Also can someone go over the sed operation here as I tried to understand this for the past 2 hours and I am not getting anywhere with this.
Questions -
1. In there , the magic is happening all because of $0=$2. Can someone please explain to me as to what does $0=$2 means ?
2. Also can someone go over the sed operation here as I tried to understand this for the past 2 hours and I am not getting anywhere with this.
best regards,
Lee.
In awk$0 refers to the whole record (line) while $1, $2 ... refer to the individual fields. So $0=$2 simply replaces the whole record with field 2.
In sed the (escaped) parentheses earmark part of a pattern for a later reference.
Take for instance this:
So basically I want to change "charlie farley" into "charlie chaplin" (or any other charlie) but leave anything else alone. I this extremely simple example I could have written
But consider this
Now I can catch "charles" or "charley" too. More general.
The \1 refers to the first earmarked pattern. But what if I do two of them?
This last example takes two strings separated by a space and reverses them, putting a comma between.
1) awk with RS set to ) doesn't break records at line ends but on occurrences of the RS char / pattern. So, the first record (also referred to as $0 in awk) is
, which is split in two at the field separator FS=\(.
then overwrites the entire record with its second field, and, because used as an awk-pattern not equal 0 (= TRUE), takes the default action print.
2) Your echotext is corrupted in your post as the second left parenthesis is missing. The sed substitutes the BRE
by first sub-expr. space second sub-expr. space third sub-expr.
Hi,
I need some advise on whether there is a better way of doing what I am currently planning to do. Perhaps I should be using arrays instead of re-directing output to files?
I need to use a tool/program named ADRCI provided by Oracle to remove trace files that it generates. Honestly it is... (1 Reply)
i have lots of files in /law/prod and /law/dev, such as AP20PD, AP20WS, AP20.scr, AP20.rpt
if i am in /law DIR
find . -name AP20PD, found in /law/prod and /law/dev
i want to head -1 AP20PD from both location and >> /tmp/test.log
can i use find and head in one line ?
----------... (1 Reply)
I know that the common use of head is for example head -3 etc.Is there any possibility that,if i have a variable that equals to an integer(i=5),i can write head -i??
If not,what syntax or commands should i write down in order to have the same result?
//maybe something lik head -"$variable" ? (2 Replies)
Im looking for a 'relatively' easy way to search through cvs to look for a particular string in the HEAD revisions.
I realize the way CVS stores versions makes this difficult. But I'm trying to come up with some script to allow this search (performance is not expected here).
Currently this... (0 Replies)
$ct=1
head -n $ct file.
When i used like this, i got an error , Bad usage of head
Cant we use variables in place of number in HEAD.
In my requirement for every iteration i should increase the number in Head and tail the last one.
HOw can i achieve this (5 Replies)
I am new to UNIX......I have one file which contains thousnads of records with header and tailer.
Header
Record 1
Record 2
....
....
Last Record
Trailer
I want to concatenate Header and Trailer in the first line....now the output should look like this:
Header: Header value, Trailer:... (2 Replies)
Hi All,
How can the head command be used to extract only a particular line.
By default head -n filename displays the first n lines. I want only the nth line.
I couldn't get it from forum search.
Thanks,
Sumesh (6 Replies)
I've a major file which includes other files and now I wanna 'cut' the file in several minor parts....like
....
find / -name "*.tmp" >filea
wc -l filea >fileb
sed -e '1s/ filea//' fileb >filec
AMOUNT=`cat filec`
if ; then
cat file a |head -100l (ell) |tail -100l >filec
cat file a |head... (6 Replies)
my boss has done it again
I have been sent to fix a unix issue
and I ma hoping you can help
three issues
1st. I have a printer that when you try to print to it the print job comes out on a diffrent printer. If I take the printer ( dot matrix thourgh a serail connection) to a diffrent local the... (3 Replies)