combing two lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting combing two lines
# 1  
Old 02-18-2011
combing two lines

Hi list,

I have to combine two lines and adding the " - " in between.

So:
Here's sentence A
Here's Senctence B

Here's sentence A - Here's Senctence B

I know how to us SED: sed '$!N;s/\n/ /' for combining tow lines. But how do
I insert the " - " correctly?

Thanks!

Martijn
(os 10.5.6, bash)
# 2  
Old 02-18-2011
Code:
 $ ruby -0777 -ne 'print $_.split("\n").join(" - ")' file

# 3  
Old 02-18-2011
Hi,

I think you were in the point. I copied your sentence adding the '-' char.
Code:
$ sed '$ !N; s/\n/ - /' infile

Regards,
Birei
# 4  
Old 02-18-2011
i would do..

a='sentence a'
b='sentence b'
c="${a} - ${b}"
echo ${c}
# 5  
Old 02-19-2011
H guys,
thanks for all the suggestions. many roads to follow..
I have a look at them.
cheers
martijn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

Python Combing Two Commands

I have been digging deeper into Python and want to make my code as efficient as possible. The less line of code the better so I have been experimenting and wanted to ask the Python gurus if this is possible. So: ... ... In : kbfileurl = re.search('<p>For more information about this... (6 Replies)
Discussion started by: metallica1973
6 Replies

4. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

5. Shell Programming and Scripting

How to combing output of cut commands with a delimiter?

While looping through a file, I am cutting different length of characters (based on their length) like columns and want to produce the output in a separate file with different columns being separated by a comma. How to achieve this with an online command. I don't want to create multiple variables... (8 Replies)
Discussion started by: mady135
8 Replies

6. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies

7. Shell Programming and Scripting

[Solved] How to create a script by combing two files?

I am trying to generate a csv file for utilization of each project directory. there are 10 filesystem and for each filesystem there are 16 directory. i was trying to create a script so i created two file. one is filesystem and one is project. so file looks like cat filesystems /app1 /app2... (10 Replies)
Discussion started by: anshu ranjan
10 Replies

8. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

9. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

10. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies
Login or Register to Ask a Question