Operating System - Linux
1748228 Members
4577 Online
108759 Solutions
New Discussion юеВ

Re: change lines in text file

 
SOLVED
Go to solution
uadm26
Super Advisor

change lines in text file

Hi, guys
I need a script to work a file whith this ouptut:

EI_FNC-ARCH-DIA
01/05/07 14:00:00

EI_TERC-ARCH-DIA
01/05/07 16:00:00

EI_PDL-ARCH-DIA
01/05/07 15:30:00

and change that output to this:
EI_FNC-ARCH-DIA|01/05/07|14:00:00
EI_TERC-ARCH-DIA|01/05/07|16:00:00
EI_PDL-ARCH-DIA|01/05/07|15:30:00

Thanks for all,
JT
5 REPLIES 5
Ivan Krastev
Honored Contributor

Re: change lines in text file

Try this one:

awk '/EI/{getline t;print $0 t;next}' filename


regards,
ivan
Peter Godron
Honored Contributor
Solution

Re: change lines in text file

Hi,
how about:
grep -v '^$' a.txt| sed '$!N;s/\n/ /' |sed "s/ /|/g" > b.txt

Remove a balnk lines
Substitute return characters
Substitute filed spaces with '|'

Input data in a.txt, output data in b.txt



Hemmetter
Esteemed Contributor

Re: change lines in text file

Hi JT

a quick and dirty shellscript:



cat datafile |
while read L1; do
if [ -z "$L1" ]; then
: # do nothing
else
read L2
echo "$L1 $L2"
fi
done | sed "s/ /|/g"




rgds
HGH
Ivan Krastev
Honored Contributor

Re: change lines in text file

Ooops forgot | :

awk '/EI/{getline t;print $0 "|" t;next}' filename


regards,
ivan
uadm26
Super Advisor

Re: change lines in text file

Ok that's it, thanks for all.