Sponsored Content
Top Forums Shell Programming and Scripting Replace values in script reading line by line using sed Post 302918877 by RavinderSingh13 on Friday 26th of September 2014 01:16:51 AM
Old 09-26-2014
Quote:
Originally Posted by crimsonengineer
So my output would be a script containing the values in the text file:

I would like my script to repeat for each row in the text file. I think this can be accomplished with sed or awk, but unsure how to piece together the proper commands. Thanks so much.
Hello,

Following may help in same.
Code:
awk '{for(i=1;i<=NF;i++){{if(i%2 != 0){print "for pa in " $i ORS "do" ORS "blah blah" ORS "done\n"} else {print "for pb in " $i ORS "do" ORS "blah blah" ORS "done\n"}}}}' Input_file

Output will be as follows.
Code:
for pa in 14.5
do
blah blah
done
 
for pb in 16.7
do
blah blah
done
 
for pa in 7.8
do
blah blah
done
 
for pb in 9.5
do
blah blah
done
 
for pa in 5.6
do
blah blah
done
 
for pb in 3.6
do
blah blah
done
 
for pa in etc
do
blah blah
done
 
for pb in etc
do
blah blah
done

EDIT: Adding more solutions for same.

Code:
awk '{for(i=1;i<=NF;i++){V=i%2 != 0?(V="pa "):(V="pb "); {print "for " V "in " $i ORS "do" ORS "blah blah" ORS "done\n"}}}'  Input_file
OR
awk '{for(i=1;i<=NF;i++){{if(i%2 != 0){V="pa "} else {V="pb "}; print "for " V "in " $i ORS "do" ORS "blah blah" ORS "done\n"}}}' Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-26-2014 at 02:32 AM.. Reason: Added 2 more solutions for same
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies

2. Shell Programming and Scripting

how can i replace / with new line in shell script or sed ?

1. how can i replace ' / ' with new line in shell script or sed ? 2. how can set a conditon untill null in while loop while ( i== null ) do ...... done (3 Replies)
Discussion started by: mail2sant
3 Replies

3. UNIX and Linux Applications

Reading values from the command line

Hi I want to give the user the choice of whether or not they want to include a certain option when they run the script. This is my getops: while getopts " s: d: r f: e h " option do case $option in f ) dsxfile="$OPTARG";; d ) dbname="$OPTARG";; s ) dsn="$OPTARG";; r )... (0 Replies)
Discussion started by: ladyAnne
0 Replies

4. Shell Programming and Scripting

how to use sed for reading from a file, line by line?

I have a file, from where I need to extract some data. But, the condition is like following : The script will read line by line,while checking if any line starts with 'MN'. If found true, it looks for if the immediate line starts with 'PQ' or not. If its true then, extract few fields from that... (1 Reply)
Discussion started by: mady135
1 Replies

5. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

6. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

7. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

8. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

9. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

10. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy