11-18-2009
How to get different lines using a for loop
Hi
I am trying to write a small AWK program to extract 324 lines which have a pattern in the line numbers.
For examples, I want to extract lines 2, 5, 7, 11 and lines like (2+662), (5+662), (7+662), (11+662) and (2+662+662), (5+662+662), (7+662+662), (11+662+662) and so on for 27 times from 'File1'.
I wrote a code like
awk '{NR==i; for (i=2; i<=27; i+=662) print NR} {NR==i; for (i=5; i<=27; i+=662) print NR} {NR==i; for (i=5; i<=27; i+=662) print NR} {NR==i; for (i=11; i<=27; i+=662) print NR}' File1> File2
I think there are quite some flaws in my code.....Plese help
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
How do I loop through the lines of a file?
Each line of the file will be the name of a server.
Like:
server1.stuff.com
server2.stuff.com
For each server I want to do a secure copy of the file to the other server.
This will be a cron job so I guess it needs to run in just SH. I... (3 Replies)
Discussion started by: jimmy
3 Replies
2. Shell Programming and Scripting
I use while do - done loop in my shell script. It is working as per my expectations.
But I do not want to process all the lines. I am finding it difficult to exclude certain lines.
1) I do not want to process blank lines as well as lines those start with a space " "
2) I do not want to... (2 Replies)
Discussion started by: shantanuo
2 Replies
3. Shell Programming and Scripting
Hi frnd , hv nice week ahead,
in shell script i found 2 words as below
1 ) targ_found=`sed -n \`echo $line_no\`p sesslog.txt | grep -ic 'Targ Rowid'`
2 ) bracket_found=`sed -n \`echo $line_no\`p sesslog.txt | grep -wc ')'`
now we got he line number of 2 words. now i want to... (1 Reply)
Discussion started by: Gopal_Engg
1 Replies
4. Shell Programming and Scripting
Hi there !
I need to treat files with variable line length, and process the tab-delimited words of each line. The tools I know are some basic bash scripting and sed ... I haven't got to python or perl yet.
So my file looks like this
obj1 0.01953 0.34576 0.04418 0.01249
obj2 0.78140... (7 Replies)
Discussion started by: jossojjos
7 Replies
5. Shell Programming and Scripting
Is this possible?
I have a for loop in a shell script reading a list, but I want each line to be a loop, not each thing with a space.
Here is the example:
HOSTLIST="\
1.2.3.4 serverA
1.2.3.5 serverB"
for NBUHOST in `echo $HOSTLIST`
do
ssh ${SERVERNAME} "echo "${NBUHOST}"... (3 Replies)
Discussion started by: LordJezoX
3 Replies
6. UNIX for Dummies Questions & Answers
Hi Dears,
I use the below code to analyze lines in a file:
for line in `cat ucsv`
do
echo $line
//analyze statements
donehowever, if line contains space char, it will be broken. for example, if file content is:
#login,full name,email,project,role,action
gmwen,Bruce... (3 Replies)
Discussion started by: crest.boy
3 Replies
7. Shell Programming and Scripting
Hi,
i am having one text file it contains some blank lines and i want to ignore that blank lines .
#! /bin/bash
clear
rdCount=0;
while read myline
do
echo $myline
let rdCount=$rdCount+1
done < ps.txt
echo "Total line=$rdCount"
and ps .txt contains the data- (17 Replies)
Discussion started by: aish11
17 Replies
8. Shell Programming and Scripting
Dear all,
I have a file like this:
imput
scaffold_0 1
scaffold_0 10000
scaffold_0 20000
scaffold_0 25000
scaffold_1 1
scaffold_1 10000
scaffold_1 20000
scaffold_1 23283
and I want the output like this:
scaffold_0 1 scaffold_0 10000
scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies
9. Shell Programming and Scripting
I have a file which has following content:
NAME=ora.DG1.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=ONLINE
NAME=ora.DG2.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=ONLINE
NAME=ora.DG3.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=ONLINE
NAME=ora.DG4.dg... (7 Replies)
Discussion started by: rcc50886
7 Replies
10. Shell Programming and Scripting
hello all,
I get data from different vendors and need to clean it up. Usually it pretty straight forward when i have files that only have headers....but in my case i have files that have a starting line of file name(and some junk info) and 2nd line is headers and the 3rd line is were the actual... (11 Replies)
Discussion started by: crazy_max
11 Replies
IGAWK(1) Utility Commands IGAWK(1)
NAME
igawk - gawk with include files
SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ...
igawk [ all gawk options ] [ -- ] program-text file ...
DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1).
AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like
@include getopt.awk
in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path.
OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports.
EXAMPLES
cat << EOF > test.awk
@include getopt.awk
BEGIN {
while (getopt(ARGC, ARGV, "am:q") != -1)
...
}
EOF
igawk -f test.awk
SEE ALSO
gawk(1)
Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995.
AUTHOR
Arnold Robbins (arnold@skeeve.com).
Free Software Foundation Nov 3 1999 IGAWK(1)