space between two lines


 
Thread Tools Search this Thread
Operating Systems Solaris space between two lines
# 1  
Old 07-12-2010
Question space between two lines

hi team


i have file test which contain

HTML Code:
 
hi how are u
hi how u doing
hellooo
gud morning 
excepted output is


HTML Code:
hi how are 
hi how u doing
 
hellooo
gudmorning
i want space between 2nd and 3rd row of the file
# 2  
Old 07-12-2010
Try it in below format...

hi how are
hi how u doing
echo " \n "
hellooo
gudmorning
# 3  
Old 07-13-2010
Quote:
Originally Posted by udhayashankar
Try it in below format...

hi how are
hi how u doing
echo " \n "
hellooo
gudmorning

its just a sample if there are 1000 lines and i need space between ever lines .
is there any command to do this . . .like SED,AWK

---------- Post updated at 11:30 PM ---------- Previous update was at 02:13 AM ----------

hi team

let me explain clearly what i want


i have a file test contain some 9 lines

HTML Code:
hi how u doing
hi helloo how r u
today is sunday
k we will go out
what u r doing here
shall we go to home
k we will meet later
i will call u tonite
take of ur pets

i want a line space between every three lines

my excepted output will be

HTML Code:
hi how u doing
hi helloo how r u
today is sunday
 
k we will go out
what u r doing here
shall we go to home
 
k we will meet later
i will call u tonite
take of ur pets

Last edited by natraj005; 07-12-2010 at 04:30 AM..
# 4  
Old 07-13-2010
Code:
#!/bin/bash

i=0
while read -r LINE
do
  if [ "$i" -eq 3 ];then
    echo ""
    i=0
  else
    echo "$LINE"
    ((i++))
  fi
done < "myfile"

# 5  
Old 07-13-2010
Quote:
Originally Posted by kurumi
Code:
#!/bin/bash
 
i=0
while read -r LINE
do
  if [ "$i" -eq 3 ];then
    echo ""
    i=0
  else
    echo "$LINE"
    ((i++))
  fi
done < "myfile"

thnks kurumi , but its shows some error

Code:
 
#!/bin/bash
i=0
while read -r LINE
do
  if [ "$i" -eq 3 ];then
    echo ""
    i=0
  else
    echo "$LINE"
    ((i++))
  fi
done < "test"

Error

Code:
-bash-3.00$ sh line.sh
line.sh: -r: is not an identifier

# 6  
Old 07-13-2010
use bash
Code:
-bash-3.00$ bash line.sh

# 7  
Old 07-13-2010
Quote:
Originally Posted by kurumi
use bash
Code:
-bash-3.00$ bash line.sh


thnks kurumi its working , but some mischange . it delete the line after 3rd line and make it as a line space . .

input

Code:
-bash-3.00$ cat  test
hi how u doing
hi helloo how r u
today is sunday
k we will go out
what u r doing here
shall we go to home
k we will meet later
i will call u tonite
shall we go out

Code:
 
bash-3.00$ cat line.sh
#!/bin/bash
i=0
while read -r  LINE
do
  if [ "$i" -eq 3 ];then
    echo ""
    i=0
  else
    echo "$LINE"
    ((i++))
  fi
done < "test"

output

Code:
 
-bash-3.00$ bash line.sh
hi how u doing
hi helloo how r u
today is sunday
 
what u r doing here
shall we go to home
k we will meet later
 
shall we go out

my excepted output is

Code:
hi how u doing
hi helloo how r u
today is sunday

k we will go out
what u r doing here
shall we go to home

k we will meet later
i will call u tonite
shall we go out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep line with all string in the lines and not space.

I want to write the syntax so does not count line with no space. So currerntly it is showing lines as 5, but i want to show 4. # cat /tmp/mediacheck | sort -u | grep -vi " " | awk '{print $1}' | wc -l BA7552 BAA002 BAA003 BAA004 (6 Replies)
Discussion started by: Junes
6 Replies

2. UNIX Desktop Questions & Answers

Adding lines to pattern space

Is there any way to add lines to the pattern space of sed? I know a bit about the N flag, but am not able to use it to do what I want which is: read a file n lines at a time. If I find a match I quit else move to the next line. e.g. if I am looking for the following three lines Hello How... (2 Replies)
Discussion started by: jawsnnn
2 Replies

3. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

4. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

5. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

6. Shell Programming and Scripting

Breaking long lines into (characters, newline, space) groups

Hello, I am currently trying to edit an ldif file. The ldif specification states that a newline followed by a space indicates the subsequent line is a continuation of the line. So, in order to search and replace properly and edit the file, I open the file in textwrangler, search for "\r " and... (14 Replies)
Discussion started by: rowie718
14 Replies

7. Shell Programming and Scripting

Remove white space at the beginning of lines

Hi! I store some data obtained with grep or awk in a file. The problem is that some lines have white space at the begining : line1 line2 line3 I use something like grep WORD INFILE >> OUTFILE awk >> OUTFILE I would love if it were possible to remove the white whitout parsing the... (4 Replies)
Discussion started by: tipi
4 Replies

8. Shell Programming and Scripting

Find lines with space between strings

Hello all, I am having trouble with setting up a regular expression used with egrep. My script reads an input file a line at a time. I would like the egrep command to search for the following pattern: server name at the beginning of the line, then one or more spaces, and then a pound sign. ... (5 Replies)
Discussion started by: Galt
5 Replies

9. UNIX for Advanced & Expert Users

Add new lines with a space in beginning

Hi file1.txt contains GigabitEthernet1/1 GigabitEthernet1/2 GigabitEthernet2/2 GigabitEthernet2/4 GigabitEthernet2/14 GigabitEthernet2/16 can anyone show me how to modify it as below. there is a space at the beginning of the next two lines . ie 'no shut' and 'switch..' !... (8 Replies)
Discussion started by: Aejaz
8 Replies

10. Shell Programming and Scripting

re: removing trailing space from lines

Not sure why this thread was closed without any explanation, but you can do what you're asking with sed 's/]*$//g' < sourceFile > destFile (1 Reply)
Discussion started by: oombera
1 Replies
Login or Register to Ask a Question