Variables in SED command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variables in SED command
# 1  
Old 01-07-2011
Variables in SED command

Hi all,

I want write a script to display 5rows at times from a input file.
my out like:
echo " display started"
r1
r2
r3
r4
r5
... Some action items...

again i need next 5 lines.



can you please advise.
# 2  
Old 01-07-2011
Code:
#!/bin/ksh
current_line=1
total_line=$(cat input_file | wc -l)
while [ $current_line -le $total_line ]; do
     awk -v c=$current_line 'NR >= c && NR < c+5' input_file
     <Some action items>
     <Some action items>
     ...........................
     ...........................
     $current_line=$(expr $current_line + 5)
done

# 3  
Old 01-07-2011
more command

Just thinking...
built-in to some flavors of unix is the more command.
so a
Code:
more testfile -n5

??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help using combining variables with sed command (RHEL 7)

Here is the whole script, very simple, but I am just learning ROK_NO=$1 RPT=/tmp/test sed -E '/^SELECT/ s/(.{23}).{8}/\1'"$ROK_NO"' /' $RPT echo $RPT When I run this I get $ bash rok.sh 2388085 : No such file or directory /tmp/test When I type the command in console, it works... (3 Replies)
Discussion started by: isey78
3 Replies

2. Shell Programming and Scripting

How to use variables in 'sed' append command?

HELLO!! I'm trying to pass a variable with in the 'sed' command (which would add some piece of code to file at a particular line). We can use sed '{line-number}a\ alfjaljf\ aslfjsfsjafl\ adlfjaf\' file.txt If file.txt is Now, I would like to add the parameter 'lmn' after... (1 Reply)
Discussion started by: mjavalkar
1 Replies

3. Shell Programming and Scripting

sed command using variables in shell script

hi guys, The following command doesn't seem to work in my shell script: tag=$(sed -n '/${line}/ s/.*\.*/\1/p' myfile.txt) When i replace the ${line} with an actual value, it works fine. So, how do i use the ${line} in this sed command? Thanks in advance, Zaff (2 Replies)
Discussion started by: zaff
2 Replies

4. Shell Programming and Scripting

replace two character strings by two variables with sed command

Hello, I want to writte a script that replace two character strings by two variables with the command sed butmy solution doesn't work. I'm written this: sed "s/TTFactivevent/$TTFav/g && s/switchSLL/$SLL/g" templatefile. I want to replace TTFactivevent by the variable $TTFav, that is a... (4 Replies)
Discussion started by: POPO10
4 Replies

5. Shell Programming and Scripting

sed: command garbled - when executed with $variables

I have got a file job_tree.lst , which contains 1 line as below $ cat job_tree.lst ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009 05:47 05/08/2009 05:50 IN 13412850/0 I want to get a child job string 3 characters offset from the parent job string (i.e. ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009... (4 Replies)
Discussion started by: Armaan_S
4 Replies

6. Shell Programming and Scripting

SED command help: Can we pass predefined variables in place of regex

Hi All, I have a doubt. Can we assign a regular expression for pattern searching to a variable in a script and then use that variable in place of a regular expression in sed command.I tried but got some syntax error!!Is it not possible.Because my requirement is that i have a generic script to get... (8 Replies)
Discussion started by: usha rao
8 Replies

7. Shell Programming and Scripting

Can i use Variables in sed command in line numbers

I wish to give line number from one point to another in sed command like this sed -n 1,1000000p file1.txt >file2.txt but variable line number $x,$x+100000 can i give it cos i tried and it was giving an error any suggestions?/ Thx in advance AC (2 Replies)
Discussion started by: bezudar
2 Replies

8. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

9. Shell Programming and Scripting

assigning variables in sed command

I need to assign a variable within a variable in a sed command. I tried doing the following in c shell. set left = 1 set right = 2 set segment = qwerty sed -n -e "/$segment{$left}/,/$segment{$right}/p" file.txt what is wrong with this syntax? (3 Replies)
Discussion started by: wxornot
3 Replies

10. Shell Programming and Scripting

Help needed in processing multiple variables in a single sed command.

Is it possible to process multiple variables in a single sed command? I have the following ksh with three variables and I want to search for all variables which start with "var" inside input.txt. I tired "$var$" but it just prints out everyting in input.txt and does not work. $ more test.ksh... (5 Replies)
Discussion started by: stevefox
5 Replies
Login or Register to Ask a Question