i have a file with following type of data
abcd : gggggg
gggggg ; 1234
gggggg ; 5678
gggggg ; 3434
gggggg ; 6565
gggggg ; 1231
1234 ; vvvv ;Eng=Myfirstname
5678 ; xyzf ;Eng=Mysecondname
3434 ; xyzf ;Eng=Mythirdname
6565 ; xyzf ;Eng=Mysfourthname
1231 ; xyzf ;Eng=Mysfifthname
now i want to create another file which will read the above file and have the above data in following format
gggggg 1234 Myfirstname
gggggg 5678 Mysecondname
gggggg 3434 Mythirdname
gggggg 6565 Mysfourthname
gggggg 1231 Mysfifthname
any help with the code is highly appreciated
Thanks
zaxxon
April 29, 2010, 6:13am
2
Not sure if you have to respond on different conditions - I left out the 2nd block with the leading g's
$> tr -d " " < infile| awk -F"[:;=]" '/^abcd/ {p=$2; next} /^[0-9]+/ {print p,$1,$4}'
gggggg 1234 Myfirstname
gggggg 5678 Mysecondname
gggggg 3434 Mythirdname
gggggg 6565 Mysfourthname
gggggg 1231 Mysfifthname
---------- Post updated at 12:13 PM ---------- Previous update was at 12:12 PM ----------
Oh and moving this to the shell scripting area - has nothing to do with UNIX and Linux Applications in particular and you might get more versatile answers.
while(<DATA>){
chomp;
my @tmp = split(/[:;=]/,$_);
map {s/\s*//g} @tmp;
if($tmp[1]=~/\d+/){
$arr[$tmp[1]]=$_;
}
elsif($tmp[0]=~/\d+/){
my $tmp = $arr[$tmp[0]].";". $tmp[3]."\n";
$tmp =~ s/\s*;\s*/ /g;
print $tmp;
}
}
__DATA__
abcd : gggggg
gggggg ; 1234
gggggg ; 5678
gggggg ; 3434
gggggg ; 6565
gggggg ; 1231
1234 ; vvvv ;Eng=Myfirstname
5678 ; xyzf ;Eng=Mysecondname
3434 ; xyzf ;Eng=Mythirdname
6565 ; xyzf ;Eng=Mysfourthname
1231 ; xyzf ;Eng=Mysfifthname
Hi all ,
Thanks for your replys ...
now i have another problem.
if in my file i have reocrd in following format
5812 ;USD
;Y;N;Y;GEMS_ ;
; ;
; ;
;DefaultParent=abc ;English=Airbaloon xyzz
ie the record is in spread in 3 line and when i do grep on it only returns me the 1st line , how can i get the whole record line
Well, it's not a record line, it's multiple lines. I take it that lines beginning with ; are continuations and everything else is a new line?
#!/bin/bash
STR=""
while IFS="" read LINE
do
[ -z "${LINE}" ] && continue
if [ ! "${LINE:0:1}" = ";" ]
then
echo "${STR}"
STR="${LINE}"
continue
fi
STR="${STR}${LINE}"
done
echo "${STR}"
HI,
i have to declare the array as shown below
set -A tech radio television mobile Engery&acc
it is giving me error for the value in bold above.
how will i add the Engery&acc value in array to be one string.
any help will be highly appreciated
Like this?
dir[2]=Engery\&acc
[root@sistem1lnx ~]# echo ${dir[2]}
Engery&acc