Jumping to next line with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Jumping to next line with awk
# 1  
Old 02-01-2005
Computer Jumping to next line with awk

I am defining an awk function (Solaris v8 ksh) of:
function firstletter {
echo "$line" | awk '{get=substr($1,1,1);print get}' | read FL
}


I am starting a wile loop with a:
for line in `cat inputfile.lst`

When I call the function from within the for loop it works great fine. From within a while loop within the for loop it doesn't pull the next line from the input file. Do I need to define a getline loop (which I'm shakey on doing) or is there another way to make the function force jumping to the next line?
Thanks in advance for any replies.

...Gozer13

Last edited by gozer13; 02-01-2005 at 06:52 PM..
# 2  
Old 02-01-2005
I diid some thing like this ...

Code:
function firstletter {
echo "$line" | awk '{get=substr($0,1,1);print get}'
}

while read line
do
     firstletter $line
done < file1

# 3  
Old 02-01-2005
Another way:
Code:
#! /usr/bin/ksh
typeset -L1 fl

while read line ; do
        fl=$line
        echo $fl is 1st char of $line
done
exit 0

# 4  
Old 02-02-2005
Another way is to use cut, e.g...
Code:
$ cat file1
aaa
bbb
ccc

$ cut -c1 file1
a
b
c

It's worth mentioning that you can redirect output to a function, e.g...
Code:
$ function firstletter {
>   cut -c1
> }

So that you can pipe the output of some command or redirect a file like this...
Code:
$ cat file1 | firstletter
a
b
c

$ firstletter < file1
a
b
c

$ < file1 firstletter
a
b
c

# 5  
Old 02-02-2005
Computer

Thanks for the tips I appriciate it so much. Unfortuanatly after pulling all my hair out, I've concluded to scrap it and start over with if then statements. Maybe throw some wile loops in there. I'm glad you guys are here to help come to these painful conclusions.

...Gozer13
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Bash script jumping too quickly to the next command - crash

Hi, (I am not too good in command-lines). I am running a bash script and at some point my loop starts to run super quickly. Then, the steps after do not get processed and there is no further outpout generated. I tried with the sleep 20s option, as I thought some steps would get overlapped, but... (22 Replies)
Discussion started by: tremblayemilie9
22 Replies

3. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

4. Solaris

jumping from one line to another

Hi, Thanks (10 Replies)
Discussion started by: rocky1954
10 Replies

5. BSD

Jumping from Solaris to BSD?

Hi all, I currently run an OpenSolaris (b134) server at home for share media between a few computers (all Macs at the moment). I use ZFS to mirror a couple of disks and have a couple of SMF manifests. My background is as a user of OS X and as a user of (Open)Solaris with formal training in... (7 Replies)
Discussion started by: forquare
7 Replies

6. Programming

Jumping to a particular line in a file

Hi, I have an output file which has more than 1,000,000,000 lines. I am accessing this file in another C++ program. Now while accessing the output file using cin, I want to jump, say, to the 5,000,000th line directly and start accessing data from there. Is this possible? Could someone please... (4 Replies)
Discussion started by: mugga
4 Replies

7. Shell Programming and Scripting

work area directory jumping script?

hi all, Ive been trying to find some way of doing this for ages but i have is a shell script that activates a python search and there it no tab completion. more familliar with tcsh at the moment but i'm a newbe. i was trying to make an easy way to browse to a list of working directories. ... (0 Replies)
Discussion started by: jvan
0 Replies

8. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies

9. Shell Programming and Scripting

script to loop and check jumping seq.

Hi, Normally, I will manually to use "ll" command to list the following file from \FILE\CACHE\ directory and check the jump seq. Can I write a script to loop or/and check jump seq file (if jumped seq and show "missing seq no" message for me) -rw-rw----+ 1 user develop 14012 Sep 4... (1 Reply)
Discussion started by: happyv
1 Replies

10. Programming

jumping to a specific line in a text file

hi everybody! i need to read a specific line from a text file using C. can any one suggest how to do it. i m aware abt fread(), fwrite(), fseek()... but using these allows the pointer to be moved 1 character at a time. Is there a way i could jump directly to a line if i know the line number?... (4 Replies)
Discussion started by: mridula
4 Replies
Login or Register to Ask a Question