Help working with lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help working with lines
# 1  
Old 06-25-2009
Help working with lines

Hello guys,

I have a little problem, i already have a txt file like:

Code:
-------------------
1
2
3
-------------------
2
3
4
5
-------------------
2
3
4

I need a script to merge in a single line al the lines between the '-------------------' line and to get a new file like:
Code:
1|2|3
2|3|4|5
2|3|4

Thanx for your help.
# 2  
Old 06-25-2009
Code:
nawk '$1=$1' RS='-' OFS='|' myFile

# 3  
Old 06-25-2009
Thanx vgersh99 but my lines are words like:
-----------------
I am
You are
he is
-----------------
she is
it is
-----------------

And your script insert '|' in each space between words, i need an output like:

I am|you are|he is
she is|it is

please your help.
# 4  
Old 06-25-2009
a lil' UUOC-ish, but..... - have to think about it.......
Code:
sed 's/^-*$//g' myFile | nawk '$1=$1' RS="" FS="" OFS="|"

# 5  
Old 06-25-2009

Code:
 awk '
  /^--*$/ && NR > 1 { print ""}
  /^--*$/ { print; next }
  { $1=$1; printf "%s|", $0 }'

# 6  
Old 06-26-2009
perl:

Code:
$/="-----------------\n";
while(<DATA>){
	s/\n/|/g;
	s/[|]?-+[|]?//;
	print $_,"\n" if $_;
}
__DATA__
-----------------
I am
You are
he is
-----------------
she is
it is
-----------------

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

4. Shell Programming and Scripting

Working with lines or variables that have spaces or special characters

Example: while read line do stat -c %G $line done < somefile.txtThe problem is that inside somefile.txt lines can have any symbol allowed as file name, like (). Even with spaces, it splits the words. somefile.txt:dira/my first jump.avi dirb/surf video (1080p).mkv (2 Replies)
Discussion started by: Tribe
2 Replies

5. Red Hat

Nslookup working but ping not working at windows client

Hi Team we have created a DNS server at RHEL6.2 environment in 10.20.203.x/24 network. Everything is going well on linux client as nslookup, ping by host etc in entire subnet. We are getting problem in windows client as nslookup working as well but not ping. all the firewall is disabled and... (5 Replies)
Discussion started by: boby.kumar
5 Replies

6. Shell Programming and Scripting

awk not working for calculating no of lines with criteria

I have tar.gz file and i want to count the lines which are matching the criteria as well as which are not matching the criteria. Following is the code Output Requirement: Match the input from zcat with 26th filed having 02 value, in case it matches then print the output in a file & increase... (12 Replies)
Discussion started by: siramitsharma
12 Replies

7. UNIX for Dummies Questions & Answers

Removing blank lines not working

In my bash script I want to echo lines in a file and ensure no blank lines are echoed:for i in $(cat txt) do echo $i | sed 's/|/ /g;s/ SEARCHTERM$//g;s/ /\r\n/g;s/^$/d' done Keep in mind this is a fragment so ignore the fact that the for loop is not closed. When I add the "s/^$/d' per... (12 Replies)
Discussion started by: MaindotC
12 Replies

8. Shell Programming and Scripting

need to read lines in file and compare value in if not working

Hello, I have this file that sometime contains 0 lines and sometimes 1 or more. It's supposed to then put the result (could be 0 or 1 or 2 or more) into a variable. Then it's supposed to echo using an if else statement depending on the value of the variable. flagvar='wc -l $tempfile |... (1 Reply)
Discussion started by: script_op2a
1 Replies

9. Shell Programming and Scripting

sed: working with multiple lines

Got another sed question :) My text block is I need to do the following: If (and only if) the line starting with 10002,11 is followed by a line starting with 10004,9 , insert the line 10003,9 between the 2 Thus, my output should be I tried but this gives me (the order... (3 Replies)
Discussion started by: orno
3 Replies

10. UNIX for Dummies Questions & Answers

Sed working on lines of small length and not large length

Hi , I have a peculiar case, where my sed command is working on a file which contains lines of small length. sed "s/XYZ:1/XYZ:3/g" abc.txt > xyz.txt when abc.txt contains lines of small length(currently around 80 chars) , this sed command is working fine. when abc.txt contains lines of... (3 Replies)
Discussion started by: thanuman
3 Replies
Login or Register to Ask a Question