Join Lines at a specific point


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Join Lines at a specific point
# 1  
Old 09-22-2012
Join Lines at a specific point

Hi I'm a beginner, and i've been having trouble joining two lines.

I need to convert this file
Code:
1097ALABAMA                Mobile County                 METHOMYL          INSE
CTICIDES                 6 1.6200000E+00 1.8000001E+00
 1003ALABAMA                Baldwin County                CHLOROPICRIN      OTHE
R PESTICIDES             4 5.9000000E+01 1.0000000E+00
 1009ALABAMA                Blount County                 CHLOROPICRIN      OTHE
R PESTICIDES            57 8.4075000E+02 1.4250000E+01
 1097ALABAMA                Mobile County                 CHLOROPICRIN      OTHE
R PESTICIDES            57 2.8500000E+03 1.4250000E+01
 1001ALABAMA                Autauga County                BENTAZON          HERB
ICIDES                 292 6.5700005E+01 8.7600006E+01
 1009ALABAMA                Blount County                 METHOMYL          INSE
CTICIDES                57 1.5390000E+01 1.7100000E+01



to look like (where they're all on one line)
Code:
1097ALABAMA                Mobile County                 METHOMYL          INSECTICIDES                 6 1.6200000E+00 1.8000001E+00
 1003ALABAMA                Baldwin County                CHLOROPICRIN      OTHER PESTICIDES             4 5.9000000E+01 1.0000000E+00
 1009ALABAMA                Blount County                 CHLOROPICRIN      OTHER PESTICIDES            57 8.4075000E+02 1.4250000E+01
 1097ALABAMA                Mobile County                 CHLOROPICRIN      OTHER PESTICIDES            57 2.8500000E+03 1.4250000E+01
 1001ALABAMA                Autauga County                BENTAZON          HERBICIDES                 292 6.5700005E+01 8.7600006E+01
 1009ALABAMA                Blount County                 METHOMYL          INSECTICIDES                57 1.5390000E+01 1.7100000E+01



thanks so much in advance!!


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.


Last edited by radoulov; 09-22-2012 at 01:52 PM..
# 2  
Old 09-22-2012
Code:
awk '{printf $0; getline; print;}' infile


Last edited by rdrtx1; 09-22-2012 at 02:12 PM..
# 3  
Old 09-22-2012
Quote:
Originally Posted by rdrtx1
Code:
awk "{printf $0; getline; print;}" infile

You need single quotes instead of double quotes to keep $0 from being expanded by the shell.
# 4  
Old 09-22-2012
As a beginner, you may not be ready for awk, so here is a simple shell script.
Code:
while read line1
do
  read line2
  echo "$line1$line2"
done

# 5  
Old 09-22-2012
For the sample input, this will work:
Code:
paste -sd'\0\n' file

# 6  
Old 09-25-2012
is this retrieved from SQL database???

I did this before

col data format a30;
col data2 format a30;
col data3 format a30;

select data as data from ......

col data format a120;

select * as data from.....
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to join Linux pc to active directory in specific ou with authconfig?

I use authconfig command to join linux computers to AD How do I specify which OU they go in? I llook at authconfig --help but not see antyhing\ Can I use --ldapbasedn=<dn> to select what OU it should go iN (0 Replies)
Discussion started by: red888
0 Replies

2. UNIX for Beginners Questions & Answers

Possible to insert a few lines of code into a file at a specific point?

Hi Folks - How would I go about inserting a chunk of lines (3) into a specific portion of a file? The background is I have a script (non shell) that it executed daily, however on Sundays, I uncomment a section of code so that piece can be run as well. So I was hoping to write a piece of... (9 Replies)
Discussion started by: SIMMS7400
9 Replies

3. Shell Programming and Scripting

Help with Round Up with 2 decimal point at specific column

Input file: USA 20.5683 UK 3.54221 Japan 2.54001 China 2.50897 Germany 2.05816 . . Desired output file: USA 20.57 UK 3.54 Japan 2.54 China 2.51 Germany 2.06 . . (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

Join Lines

Hi how do I join files like below in script. Thanks, Ashan there are may line like this in the file. zone name DR_TMP_A_sev1_3eA vsan 200 pwwn 50:00:09:73:f0:16:35:08 pwwn c0:50:76:08:6e:dc:00:16 zone name DR_TMP_A_SVR2_3eA vsan 200 pwwn 50:00:09:73:f0:16:35:08 pwwn... (4 Replies)
Discussion started by: ashanabey
4 Replies

5. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

6. Shell Programming and Scripting

Html parsing - get line after specific string till a point

Hi all :) It sounds complex, for example I want to find the whole html file (there are 5 entries of this string and I need to get all of them) for the string "<td class="contentheading" width="100%">", get the next line from it only till the point that says "</td>", plus removing \t (tabs) ... (6 Replies)
Discussion started by: hakermania
6 Replies

7. Shell Programming and Scripting

Bash take word after specific point and till next space?

Hello, I have an output like Interface Chipset Driver wlan0 Intel 4965/5xxx iwlagn - and I want to take only the 'wlan0' string. This can be done by a="Interface Chipset Driver wlan0 Intel 4965/5xxx iwlagn - " b=${a:25:6} echo $bThe thing is that wlan0 can be something else, like eth0 or... (2 Replies)
Discussion started by: hakermania
2 Replies

8. Homework & Coursework Questions

How join works and the specific parameters to my problem?

1. The problem statement, all variables and given/known data: I have two files created from extracting data off of two CSV files, one containing class enrollment on a specific quarter and the other containing grades for that specific quarter. The Enrollment file generated contains course name,... (11 Replies)
Discussion started by: Lechnology
11 Replies

9. Shell Programming and Scripting

Removing all characters on and before specific point

Im having a file with records DB1635 |Y|N|DB1632 |000024968_202 |0|000024968302|RCF02| DB1636 |Y|N|DB1633 |000024968_203 |0|000024968302|RCF02| i want to get output as Y|DB1632 |RCF02| Y|DB1633 |RCF02| how can i do this ?? any... (3 Replies)
Discussion started by: Trendz
3 Replies

10. Shell Programming and Scripting

Test to see if a drive is mounted at a specific point

I have a script that backs up our storage drive daily to one external drive and weekly to another. What I'd like to do is find a way, in the script, to test whether the drives are mounted so that it doesn't accidentally fill up the main drive in the event of a drive failure, etc. Any ideas on how... (1 Reply)
Discussion started by: spectre_240sx
1 Replies
Login or Register to Ask a Question