Display mutiple line in single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display mutiple line in single line
# 1  
Old 11-11-2008
Display mutiple line in single line

Hi All,

I had a file called Input.txt, i need to group up in a single line as 1=ttt and the no of lines may vary bewteen the 1=ttt

Code:
 
cat Input.txt
1=ttt,2=xxxxxx, 3=4545
44545, 4=66667
7777, 5=77723
1=ttt, 2=xxxxxx, 3=34436 66
3545, 4=66666, 5=ffffff, 6=uuuuuuu
1=ttt, 2=xxxxxx, 3=311343545, 4=66666
1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD
 
O/p :
 
1=ttt,2=xxxxxx, 3=454544545, 4=66667 7777, 5=77723
1=ttt, 2=xxxxxx, 3=34436 663545, 4=66666, 5=ffffff, 6=uuuuuuu
1=ttt, 2=xxxxxx, 3=311343545, 4=66666
1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD

# 2  
Old 11-11-2008
Try awk
Code:
awk 'NR!=1 && $1 ~ /1=/{printf "\n"}{printf}' file

# 3  
Old 11-11-2008
Hi,

It gives error as,

awk: syntax error Context is:
>>> NR!=1 && $1 ~ /1=/{printf "\n"}{printf} <<<

i had changed the printf to print and tried, o/p as

awk 'NR!=1 && $1 ~ /1=/{print "\n"}{print}' Input.txt
1=ttt,2=xxxxxx, 3=4545
44545, 4=66667
7777, 5=77723

1=ttt, 2=xxxxxx, 3=34436 66
3545, 4=66666, 5=ffffff, 6=uuuuuuu, 7=ooooooo

1=ttt, 2=xxxxxx, 3=311343545, 4=66666

1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD
# 4  
Old 11-11-2008
Hey, i had tried in nawk.. its working fine..

Thanx
# 5  
Old 11-11-2008
perl:

Code:
undef $/;
open FH,"<a" or die "Can not open file";
$str=<FH>;
$str=~tr/\n//d;
@arr=split("1=ttt",$str);
print "1=ttt$_\n" foreach(grep { length($_)>1 } @arr);
close FH;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

5. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

6. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

8. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

9. UNIX for Advanced & Expert Users

Remove first line from mutiple files

How to remove the first line from multiple files and use it as source to the jobs. Only at the runtime it should remove the first line not in the file . (1 Reply)
Discussion started by: etldeveloper
1 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question