I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output
which was given by the grep.
sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202*
Output:
PDEWG511_TVLI_JOB_STATS.ksh.20120214_1331.log:nazeer|Wed Feb 15 13:28:04
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:35:27
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223336.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:37:25
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223527.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:38:48
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223725.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:40:45
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223848.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:42:42
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224046.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:45:50
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224415.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:47:30
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224550.csv|
I tried to pipe the output of the grep to awk as below which didn't worked out
grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* | awk -F"|" '{ print $5 }' | awk -F"/" '{
print $6 }' > demo.txt
I am little aware that awk needs a file to look for the field seperator.
Is there any way I can achieve my task without creating intermediate files??
kalpeer
2
When i execute your command i am getting the below output.
Its not mandatory to have file for awk.
Is this is the expected output ?
Thanks,
Kalai
1 Like
Hi Kalai..
I need the field(file name) next to CF, for example TVLI_STATS_NRT_XLSTWS03_20120212_224550.csv|
For me the command didn't worked. Could u plz post the command u tried...
kalpeer
4
Just modified your command little,
Output:
Whats your platform ? uname -a
1 Like
Or put all commands in one awk:
awk -F'[/|]' '/C10_Subscribe.000\|subscribe\|newfile\|/{print $(NF-1)}' infile
1 Like
ctsgnb
6
sed '/|$/!d;s:.*/::;s:|$::' infile
$ cat tst
PDEWG511_TVLI_JOB_STATS.ksh.20120214_1331.log:nazeer|Wed Feb 15 13:28:04
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:35:27
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223336.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:37:25
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223527.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:38:48
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223725.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:40:45
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_223848.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:42:42
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224046.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:45:50
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224415.csv|
PDEWG511_TVLI_JOB_STATS.ksh.20120212_1330.log:nazeer|Sun Feb 12 22:47:30
2012|C10_Subscribe.000|subscribe|newfile|/opt/etl_sources/edw/stats/CF/TVLI_STATS_NRT_XLSTWS03_20120212_224550.csv|
$ sed '/|$/!d;s:.*/::;s:|$::' tst
TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv
TVLI_STATS_NRT_XLSTWS03_20120212_223336.csv
TVLI_STATS_NRT_XLSTWS03_20120212_223527.csv
TVLI_STATS_NRT_XLSTWS03_20120212_223725.csv
TVLI_STATS_NRT_XLSTWS03_20120212_223848.csv
TVLI_STATS_NRT_XLSTWS03_20120212_224046.csv
TVLI_STATS_NRT_XLSTWS03_20120212_224415.csv
TVLI_STATS_NRT_XLSTWS03_20120212_224550.csv
1 Like
Thanks to all...
I made a silly mistake in the command. I had wrongly specified the field position as 6 instead of 7 in awk
After correcting it, the command worked.
Sorry for the inconvenience.
---------- Post updated at 03:49 AM ---------- Previous update was at 03:48 AM ----------