Need a script to create specialized output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a script to create specialized output file
# 1  
Old 03-10-2016
Need a script to create specialized output file

I need a script to process the (space-separate) values for each line as seen in the below input file and then output the data into an output file as follows. We have been unable to create this using typical bash scripting and cold not find anything out on the internet similar to what we are trying to accomplish. Any help would be appreciated.

Input file example:
Code:
 
Name1 addr1 100 101
Name2 addr2 200 201

etc...

Output file example:
Code:
 
Name=Name1
Address=addr1
ID1=100
ID2=101
Name=Name2
Address=addr2
ID1=200
ID2=201

etc...

Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) when displaying full-line and multi-line sample input, sample output, and and code segments.

Last edited by Don Cragun; 03-10-2016 at 11:19 PM.. Reason: Change ICODE tags to CODE tags.
# 2  
Old 03-10-2016
try:
Code:
while read name address id1 id2
do
   if [ -n "$name" ]
   then
      echo "Name=$name"
      echo "Address=$address"
      echo "ID1=$id1"
      echo "ID2=$id2"
   fi
done < infile


Last edited by rdrtx1; 03-10-2016 at 08:11 PM..
# 3  
Old 03-10-2016
I tried to answer this, but ran into my own problems using sed
Code:
s/\([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\)/Name=\1\nAddress=\2\nID1=\3\nID2=\4/

My input file:
Code:
Name1 adr1 100 101
Name4 add2 200 201

But my output came out like this: the backslash n didn't do anything.
Code:
Name=Name1nAddress=adr1nID1=100nID2=101
Name=Name4nAddress=add2nID1=200nID2=201

# 4  
Old 03-10-2016
Thank you both for your responses.

rdrtx1 - Your code was exactly what was needed and is much appreciated.

Thanks much!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk and sed script to create one output CSV file

Hi All , I would require your help to generate one output file after post processing of one CSV file as stated below This file is just a small cut from a big file . Big file is having 20000 lines PATTERN,pat0,pat1,pat2,pat3,pat4,pat5,pat6,pat7,pat8,pat9... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

How to create a file from output of vertica table query in UTF-8 format?

Hello, In my shell script, I extract table data from HP Vertica DB into a csv file using vsql -c command. But the problem is the file getting created is in binary format and hence some of the data becomes unreadable which has chinese characters as part of data. file -i filename.csv - gives... (2 Replies)
Discussion started by: Dharmatheja
2 Replies

3. Shell Programming and Scripting

Specialized grep script

I have been (unsuccessfully) trying to write a script that will do the following: for each line of an input file (that contains IP address), the script searches the target file for any lines containing said IP address if it finds a line (or lines) it writes the line(s) to output if the line is... (4 Replies)
Discussion started by: ddirc
4 Replies

4. UNIX for Dummies Questions & Answers

Create csv with output filenames and file size

Hello All, Here is seeking a bit of help in trying to solve a problem. I am required to create a csv file as shown below: output.csv -> output_1,output_2,output_3,...,output_<N> filename1:20,filename2:30,filename3:30,...,filename<N>:30 by listing output_1, output_2,... , output<N> as... (3 Replies)
Discussion started by: vkumbhakarna
3 Replies

5. UNIX for Dummies Questions & Answers

Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all, I have a flat file as below; 470423495|1||TSA-A000073800||1|||1 471423495|1||TSA-A000073800||5|||5 472423495|1||TSA-A000073800||2|||7 473423495|1||TSA-A000073800||3|||3 I like to create a Unix script. The script have to valuate the last two columns, if the values are... (4 Replies)
Discussion started by: mrreds
4 Replies

6. Shell Programming and Scripting

Need specialized random string generator script

Hi, I need a script that will generate a set of random strings in sequence, with the ability to predetermine the length, quantity, and alphabet of individual string, and to use the outputs of earlier strings in the sequence to define the parameters of later strings. For examples, I might want... (5 Replies)
Discussion started by: vajrajames
5 Replies

7. AIX

create file and name it with same output name !

Guy's I have this command echo $? when I type it in AIX it will showme 0 I want when I type that command to create file in the same location with the same output of echo $? For exampl : I will execute the command now .... P_server/root/echo $? 0 the output is 0 so I want... (2 Replies)
Discussion started by: Mr.AIX
2 Replies

8. Shell Programming and Scripting

to create an output file as a table

Hi, I have four input files and would like to create an output file as a table. Please check the example below. File 1. 111111 222222 333333 444444 File 2. 555555 666666 777777 888888 File 3. aaaaa bbbbb ccccc ddddd (2 Replies)
Discussion started by: marcelus
2 Replies

9. Shell Programming and Scripting

how to create a logfile to track the below script output

Hi Dudes, Can you please suggest me how to create a logfile to track the below script output ? Thanks #!/bin/ksh # backup the "std" I/P file descriptor exec 5<&0 #echo "Proceed ?" while read config_line; do # backup the I/P file descriptor of "while" block exec 6<&0 # restore the... (2 Replies)
Discussion started by: shirdi
2 Replies

10. Shell Programming and Scripting

Applying diff output to create new script

I believe I read somewhere that you can do a diff of two ksh scripts and use the output to create a new script with the differences. :p Could someone please show me the command(s) I'd need to use to get this accomplished? Or perhaps point me to a thread that explains this in detail. Thanks... (1 Reply)
Discussion started by: BCarlson
1 Replies
Login or Register to Ask a Question