Hi all,
Please help me in providing sample code to append the following 4 lines in one row.
Input :
A1/EXT "BAPBSC10/07B/00" 523 090530 0115
RXOCF-430 HY1711 1
EXTERNAL ALARM
DOOR ALARM
Output should be :
A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 DOOR ALARM
With the tr command you can replace the newline character (\n) with a space.
Read the man page.
consider yout temp file (temp_file) contains:
A1/EXT "BAPBSC10/07B/00" 523 090530 0115
RXOCF-430 HY1711 1
EXTERNAL ALARM
DOOR ALARM
___________________________
#!/usr/bin/ksh
str_tmp=""
while read line
do
str_tmp="${str_tmp} ${line}"
done<"temp_file"
echo "$str_tmp"
OUTPUT:
A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM DOOR ALARM
awk '{ printf ("%s ",$0) }' input_file.txt
Hi Gajanan,
Thanks for ur reply..for single its working.if i have more lines then output is not coming properly..
I/P FILE :
A1/EXT "BAPBSC10/07B/00" 523 090530 0115
RXOCF-430 HY1711 1
EXTERNAL ALARM
DOOR ALARM
HIGH TEMPERATURE
A1/EXT "BAPBSC10/07B/00" 963 090530 0658
RXOCF-510 HYD774 1
EXTERNAL ALARM
RECTIFIER FAIL
A1/EXT "BAPBSC10/07B/00" 012 090530 1432
RXOCF-288 HYD188 1
EXTERNAL ALARM
LOW BATTERY VOLTAGE
Ouput file Should be :
A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM RECTIFIER FAIL
A1/EXT "BAPBSC10/07B/00" 012 090530 1432 RXOCF-288 HYD188 1 EXTERNAL ALARM LOW BATTERY VOLTAGE
awk '/A1/ { printf ("\n%s", $0);next} {printf ("%s",$0)}' inputfile.txt
sudhakar,
Hi Gajanan,
Thanks for ur reply..for single its working.if i have more lines then output is not coming properly..
you did n't mention proper input in your first post.Post should be informative from next time pls.
use:
cat temp_file |tr -d "\n"
tr (Translate) will delete new line charterer [\n]
cat temp_file |tr -s "\n" " "