Dear all
From below mention input file I needed op file as show below. I am using below code but not worked.
I/p file
BSCBCH1 EXAL-1-4 WO* SMPS MAINS FAIL
BSCBCH1 EXAL-1-5 WO* SMPS RECTIFIER FAIL
BSCBCH1 EXAL-1-6 WO* SMPS MAJOR ALARM
BSCBCH2 EXAL-1-10 WO* AC2 UNIT FAIL
BSCBCH2 EXAL-1-14 WO* AC1 UNIT FAIL
o/p file:
BSCBCH1 SMPS MAINS FAIL
BSCBCH1 SMPS RECTIFIER FAIL
BSCBCH1 SMPS MAJOR ALARM
BSCBCH2 AC2 UNIT FAIL
BSCBCH2 AC1 UNIT FAIL
below code not worked:
awk '{a=$1} /WO/ {b=$4} {print a b}' finename.txt
Thanks in advance.
Regards
Jaydeep
vbe
2
because you have not displayed the other fields...
awk '{a=$1} /WO/ {b=" "$4" " $5" " $6} {print a b}' filename.txt
Not necessary to use variables, this should be sufficient:
awk '/WO/ {print $1, $4, $5, $6}' filename.txt
CarloM
4
Given that your file appears to be fixed-width format rather than delimited, it might be easier (and safer) to just use man cut ("posix").
Yoda
5
awk 'sub(/ .*WO\* */," ")' file
Hello All,
Some more approaches.
sed 's/\(.*\)\(\ WO\* \)\(.*\)/\1\3/g' file_name
awk '/WO\*/ {print $1OFS$2OFS$4}' file_name
awk '/WO\*/ gsub(/ WO\* /,X,$0) {print}' file_name
Thanks,
R. Singh