- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Making 5 lines into 1
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2002 06:48 AM
тАО02-27-2002 06:48 AM
For eg:
I have 100 lines which
could read in a single line
and so on , +++11 122321
I have 200 lines which
could read in a single line
The result would be :
I have 100 lines which could read in a single line and so on , +++11 122321.
I have 200 lines which could read in a single line
Thanks in advance
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2002 06:56 AM
тАО02-27-2002 06:56 AM
Re: Making 5 lines into 1
cat textFile | while read line
do
print "$line \c" >> newTextFile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2002 06:57 AM
тАО02-27-2002 06:57 AM
Re: Making 5 lines into 1
eg cat file1 |awk '{printf("%-s", $0)}'
This will not print line feeds by default.
If you want to group by a certain number of lines, then increment a counter in the awk command and every time it reaches the limit, perform a 'printf("\n")'.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2002 07:02 AM
тАО02-27-2002 07:02 AM
Re: Making 5 lines into 1
You could do something like this. I don't know how long your possible text string can be so you might need to change the 130 value.
awk ' $0~/^I have 100/
{ TXT = substr($0,1,130);
}
{ printf "%s\n",TXT } ' input.file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2002 07:24 AM
тАО02-27-2002 07:24 AM
Re: Making 5 lines into 1
awk ' $0 ~ "^I have" {
printf "%s", $0
times=$3+0
for (i=1 ; i< times; i++) {
getline
printf "%s", $0
} ; printf"\n"}' <
could read in a single line
and so I have on , +++11 122321
I have 2 lines which
could read in a single line
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2002 12:40 AM
тАО02-28-2002 12:40 AM
Re: Making 5 lines into 1
Thanks a lot,
Carlos,
Thanks ,it works but what if the lines are > than 4 lines , and should have a carriage return when the word "I have" appears. Perhaps
my explanation was blurry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2002 12:48 AM
тАО02-28-2002 12:48 AM
Re: Making 5 lines into 1
Taking bryan's solution,
#!/sbin/sh
cat textFile | while read line
do
if echo $line|grep "I have" >/dev/null 2>&1
then
print "\n" >> newTextFile
fi
print "$line \c" >> newTextFile
done
Hope this helps. Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2002 01:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2002 02:18 AM
тАО02-28-2002 02:18 AM
Re: Making 5 lines into 1
Thanks a ton, now finallay could you break it up in english especially the "sep" part
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2002 03:07 AM
тАО02-28-2002 03:07 AM
Re: Making 5 lines into 1
awk '
/^I have/{printf "%s%s ",sep,$0;sep="\n";next}
{printf "%s",$0}
END{print}
' yourfile
Until it's explicitly defined, the sep variable will be empty - therefore the first time "I have" is encountered, this will be the case, and it will print this line without a leading carriage return (CR). Once this has happened, sep is then defined as a CR, so that subsequent "I have" matches ARE preceded by a CR. All other lines are printed as found. The END statement ensures the last line finished off with a CR.
Rgds, Robin.