- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Insert blank line
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
тАО10-08-2002 09:52 PM
тАО10-08-2002 09:52 PM
Insert blank line
Im trying to read a text file with 5 fields and insert a blank line after every two records or lines. Could somebody help me with a script to do read the file and insert a blank line after reading every 2 lines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 10:24 PM
тАО10-08-2002 10:24 PM
Re: Insert blank line
awk '{line[NR]=$0}
END {
for ( i=1;i<=NR;i++)
{ print line[i]; if ( i%2 == 0 ) print}
}' textfile
textfile like this:
a1 a2 a3 a4 a5
b1 b2 b3 b4 b5
c1 c2 c3 c4 c5
d1 d2 d3 d4 d5
e1 e2 e3 e4 e5
f1 f2 f3 f4 f5
results in
a1 a2 a3 a4 a5
b1 b2 b3 b4 b5
c1 c2 c3 c4 c5
d1 d2 d3 d4 d5
e1 e2 e3 e4 e5
f1 f2 f3 f4 f5
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 11:28 PM
тАО10-08-2002 11:28 PM
Re: Insert blank line
this should do what you want:
#!/usr/bin/sh
# insert blank after CH_NUMBER of lines
CH_NUMBER=2
NUMBER=0
cat $1 | while read line
do
if [ $NUMBER -eq $CH_NUMBER ]
then
echo ""
NUMBER=0
fi
let NUMBER="$NUMBER + 1"
echo $line
done
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2002 12:55 AM
тАО10-09-2002 12:55 AM
Re: Insert blank line
Another awk solution:
awk '{ getline a ; getline b ; print a",\n",b,"\n"}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2002 02:45 AM
тАО10-09-2002 02:45 AM
Re: Insert blank line
Another:
# awk '{if (NR%2==1) {print $0} else {print $0"\n"}}' filename
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2002 05:14 AM
тАО10-09-2002 05:14 AM
Re: Insert blank line
# add a blank line every 2 lines (after lines 2,4,6 etc.)
gsed '0~5G' # GNU sed only
sed 'n;G;' # other seds
sed 'n;G;' test > test1
Now test1 has blank line after ever 2 lines.
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2002 08:07 AM
тАО10-09-2002 08:07 AM
Re: Insert blank line
This PERL gem works ($. is the input line #):
perl -ne 'print; print "\n" if $.%2==0;' file0 > file1
This following does NOT work because it prints the input line after the code snippit is processed:
perl -pe 'print "\n" if $.%2==0;' file0 < file1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2002 11:50 PM
тАО10-09-2002 11:50 PM
Re: Insert blank line
A little more terse:
perl -ne 'print $_,($.%2)?undef:"\n";'