Sponsored Content
Top Forums Shell Programming and Scripting Splitting Single line into multiple line Post 302863795 by Don Cragun on Tuesday 15th of October 2013 06:57:09 AM
Old 10-15-2013
Assuming that you really want to translate "connectorX" from your input to "connectionX" in your output, and that you might want to feed multiple lines into this script, the following seems to do what you want:
Code:
awk '
{       mc = 0
        for(i = 2; i < NF; i += 2) {
                c = substr($i, 10) + 0
                if(c != 7 && c != 13) {
                        p[c] = $(i + 1)
                        if(c > mc) mc = c
                }
        }
        lc = 0
        for(i = 0; i <= mc; i++)
                if(i in p) {
                        if(lc++ == 0) o = $1
                        o = o "  connection" i "  " p[i]
                        if(lc == 3) {
                                print o
                                lc = 0
                        }
                        delete p[i]
                }
        if(lc) print o
}' file

This could be simplified slightly if you will always only process one line at a time.
If each line to be processed always has connector0 through connector12 (except for connector7) and connector7 and connector13 might also appear, but no others, it could be simplified some more. I will leave those simplifications as an exercise for the reader.

With your sample input, this script produces:
Code:
U_ABC  connection0  pin21E  connection1  pin22E  connection2  pin23E
U_ABC  connection3  pin24E  connection4  pin25E  connection5  pin26E
U_ABC  connection6  pin27E  connection8  pin26F  connection9  pin25F
U_ABC  connection10  pin24F  connection11  pin23F  connection12  pin22F

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single line into multiple lines

I have a case where, I need to look into a file. Go to each line of the file, find the length of the line, if the length of the line is more than 75 chars, I need to split the line into multiple lines of 75chars max. If the length of the line is less than 75, we need not do anything. So at the... (4 Replies)
Discussion started by: thanuman
4 Replies

2. Shell Programming and Scripting

Splitting the line in multiple lines

Hi Guys, I need a help. I am pretty new to the shell level programing. I was trying to split a long lines to a multiple lines with few conditions. I goggle for the code and found some snippets and tried to modified it but I got few strange problems too. I have to split the lines if line is ... (3 Replies)
Discussion started by: dd_sh
3 Replies

3. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

4. Shell Programming and Scripting

make multiple line containing a pattern into single line

I have the following data file. zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii I want to make 2nd field pattern matching multiple lines... (13 Replies)
Discussion started by: VTAWKVT
13 Replies

5. Shell Programming and Scripting

Single to multiple line file

I am working with single line file with 589744523 characters having 542 "^M" (line feed) character. I want to make 542 different lines file from the single line file thr. shell program only (it can be done thr vi command) rd anil sorry for duplicate post previously, actually i don,t know... (6 Replies)
Discussion started by: anil_kut
6 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

splitting a huge line of file into multiple lines with fixed number of columns

Hi, I have a huge file with a single line. But I want to break that line into lines of with each line having five columns. My file is like this: code: "hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","you." I want it like this: code:... (1 Reply)
Discussion started by: rajsharma
1 Replies

8. Shell Programming and Scripting

convert single line output to multiple line

Hi all, I have a single line output like below echo $ips 10.26.208.28 10.26.208.26 10.26.208.27 want to convert above single line output as below format. Pls advice how to do ? 10.26.208.28 10.26.208.26 10.26.208.27 Regards Kannan (6 Replies)
Discussion started by: kamauv234
6 Replies

9. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

10. Shell Programming and Scripting

Splitting one line into multiple lines

Hi, I have one problem scenorio as below. my source file is : cat input_file. "hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","y ou." my output should be like. "hi","there","how","are","you?", "It","was","great","working","with",... (7 Replies)
Discussion started by: abhilash_nakka
7 Replies
VM(1)								      mgetty								     VM(1)

NAME
vm - VoiceModem is the program for handling the voice modem functionality from shell scripts ACTIONS
beep options [<frequency [<length in 0.001sec>]]> diagnostics options device name (e.g. ttyS2 dial options phone number help play options [<file names]+> record options file name shell options [<shell script [shell options]]> wait options [<time in seconds]> devicetest OPTIONS
-c n use compression type n -d n set i/o device -t, -m, -i, -e, -s, -H equals to -d <2,3,4,5,6,7> -l s set device string (e.g. -l ttyS2:ttyC0) -v verbose output -w use off / on hook signal from local handset to start and stop recording -x n set debug level -L n set maximum recording length in sec -P print first DTMF tone on stdout and exit -R read and print DTMF string on stdout and exit -S s set default shell for shell scripts (e.g. -S /bin/sh) -T n set silence timeout in 0.1sec -V n set silence threshold to <n> (0-100%%) SEE ALSO
vgetty(1) POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 30: You forgot a '=back' before '=head1' Around line 32: '=item' outside of any '=over' Around line 71: You forgot a '=back' before '=head1' perl v5.10.1 2010-04-04 VM(1)
All times are GMT -4. The time now is 03:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy