First I apologize for my novice question. I'm still learning sed & awk.
I have a file with the following data format:
This file contains over 8000 data lines in which the path may be more or less then what is shown. I've been requested to do a simple format (or so I thought) on the file to look like the following:
There is a tab that replaces the last slash character which will seperate the last field.
To start, The first awk line I've used to do this is: awk -F"/" '{$NF=""}1'
I know this kills the last $NF, but again, I'm just learning this (getting what I can from the Sed & Awk, O'Reilly book), and am trying to separate the filename from the path of a single line.
I've searched through numerous threads, and even though I know there is a solution available, I couldn't find one.
Your help and explanations would be greatly appreciated!
Yes it should be \1 rather than & of course :roll eyes:
--
Just one note about the use of awk. RudiC and my approach will give the same result in most cases.
However, if $NF is used in the matching part (the first field) of the sub() function and it contains special regular expression characters then that may give undesired results.
The first field is interpreted as ERE, an extended regular expression (unless it consists of a single character in double quotes)
There is no problem with using $NF in the replacement part of the sub() function (the 2nd field), since that is a string.
Last edited by Scrutinizer; 09-30-2015 at 03:29 PM..
I found this command and would like to know what it means:
gawk 'NR==1{for(i=1;i<=NF;i++)if($i~/FE/)f=i}{for(i=0;i<n;i++)printf"%s%s",i?" ":"",$f;print""}'
It seems to mean if the row =1 assign i to that row, and then if FE is in the top row /column then increment and print the row.
I am... (2 Replies)
Hi,
I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1).
Input:
919143110065
919143110065
919143110052
918648846132
919143110012
918648873782
919143110152
919143110152
919143110152... (2 Replies)
Hi,
My input files is like this
axis1 0 1 10
axis2 0 1 5
axis1 1 2 -4
axis2 2 3 -3
axis1 3 4 5
axis2 3 4 -1
axis1 4 5 -6
axis2 4 5 1
Now, these are my following tasks
1. Print a first column for every two rows that has the same value followed by a string.
2. Match on the... (3 Replies)
Experts:
LINE1 :This is line one The FIRST line of the file.
LINE2 :This is line two
LINE3 :This is line three with 8 fileds
LINE4 :This is line four
LINE5 :This is line five
LINE6 :This is line six with 8 fileds
I want to delete line 1, and then process the file and want to print lines... (2 Replies)
Hello, I have an input file like
123,456,789,321,654,987,IN,OUT,2012,000075,CF34EQ
It has 11 fields separated by comma. I am trying to do this
while read string
do
var=$(echo $string | awk -F"," '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}')
set -- $var
echo $1
...
...
echo $10... (3 Replies)
I am modifying someone else's code. There is a foreach statement printing the contents of a hash.
Can someone give me an example of printing the last element in a hash?
The output currently is
A
B
C
D
E
I want the output to be
E (1 Reply)
Hello friends, can any one tell what is meaning of this
awk '{print NR ". " $0}' phonebook
i just want to know what is ". " and $0 mean in this.
thanks (2 Replies)
Actually I got a list of file end with *.txt
I want to use the same command apply to all the *.txt
Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics.
For example:
I got the file below:
file1.txt
file2.txt
file3.txt... (4 Replies)
The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }'
I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ".
Thanks. (2 Replies)