Basic awk question...getting awk to act on $1 of the command itself


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Basic awk question...getting awk to act on $1 of the command itself
# 1  
Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk.

This is the contents of test.sh
Code:
awk '{print $1}'

From the prompt if I enter:
./test.sh Hello World
I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello World" will I see "Hello" echoed. (and then I am not able to get back to the prompt without sending a break)

I have some scripts that use a Nokia program where I can enter:
./nokia.sh 41
and it will execute a task on a network element 41. I am attempting to use awk to format the input to one of these nokia programs, but I am not able to get awk to act on $1 of the command itself. I don't want to have to create a file where the sole content is "41" in order to get awk to format it.

All of my literature and searching only shows examples where the awk script refers to another file.

Thanks in advance.
# 2  
You are confused with the the first parameter of the script and the first field of awk. To print the first word of the shell parameter with awk it should be something like:

Code:
echo "$1" | awk '{print $1}'

Regards
# 3  
Ahhhhhhh. I knew it was a very simple solution. Thanks for your help.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #794
Difficulty: Medium
1/10 has a finite binary representation.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Basic Linux command line question

:D:D:D These are list of command i typed on opensuse terminal and evolve lots of doubt around ,that i can't answer. COMMAND 1 linux-xavv:/ # cd COMMAND 2 linux-xavv:~ # Does above command 1 and command two with red labelled sign make different meaning or same . 1 linux-xavv:/... (1 Reply)
Discussion started by: lobsang
1 Replies

2. Homework & Coursework Questions

Question about awk command

hi gurus, I am not sure what the below commands does. awk 'BEGIN {sum=0} {sum=sum+$5} END {print sum}' input_file (4 Replies)
Discussion started by: ramkumar15
4 Replies

3. UNIX for Dummies Questions & Answers

Basic loop awk/shell script question..

Hi, Sorry if this is a newbie question. I guess you can use either awk or shell script for this sequence of operations, but knowing very little about either of them I'm not sure how I should try to write this. The basic objective is to copy certain files that are scattered all over my... (10 Replies)
Discussion started by: pc2001
10 Replies

4. Shell Programming and Scripting

Question about a awk command

Hi, I am studying an awk command: awk '{ sub(/\/\/.*/, "", $NF); print }' input.txt The input.txt is: char*s1="//hello"; //comment //delete /* hello //*/ The output is : char*s1="//hello"; /* hello (2 Replies)
Discussion started by: jeffwang66
2 Replies

5. IP Networking

iptables nat/masquerade - how to act as a basic firewall?

edit: SOLVED - see below for solution Hi there, I've inherited a gob of Linux hosts and so am learning linux from the bottom of the deep end of the pool (gotta say I'm warming up to Linux though - it's not half bad) Right now iptables is confusing me and I could use some pointers as to how... (0 Replies)
Discussion started by: Smiling Dragon
0 Replies

6. Shell Programming and Scripting

AWK printf command question

Hi, I am using below awk code to convert a csv file data into fixed file format. awk 'BEGIN { FS = "," fmt = "%10s%010d%10s%d%1d\n" } NR>1 { printf fmt, $1, $2, $3, $4*100, $5 }' /data/mydata.csv > /data/fixed.dat Data in mydata.csv ================... (2 Replies)
Discussion started by: kbmkris
2 Replies

7. UNIX for Dummies Questions & Answers

AWK printf command question

Hi, I am using below awk code to convert a csv file data into fixed file format. awk 'BEGIN { FS = "," fmt = "%10s%010d%10s%d%1d\n" } NR>1 { printf fmt, $1, $2, $3, $4*100, $5 }' /data/mydata.csv > /data/fixed.dat Data in mydata.csv ================... (1 Reply)
Discussion started by: kbmkris
1 Replies

8. Shell Programming and Scripting

awk script need to act on same file on matced case

Hello, I have a log file , i want to delete the lines of the log file which is match with 1st and 5th field with different patterns. Once it will meet with that condition it will delete that line from the log . I dont want to create any temp file over there. Successfully able to retrieve the... (1 Reply)
Discussion started by: posix
1 Replies

9. UNIX for Dummies Questions & Answers

Basic IF Command Question

Hi, I have a months worth of data that I need to separate into weekly files. There is a date column with dates in the following format: YYYYMMDD. I'm thinking I can create the weekly files by using a grep command combined with an IF command and specify each day of the specific week I'm... (1 Reply)
Discussion started by: cwl
1 Replies

10. UNIX for Dummies Questions & Answers

awk and find command question

Hello! I have written this script: for file in "$( find $dirName -type d )" do echo "$file" echo "hello" done but as a result I get all the directories and in the end the work "hello". Shouldn't it print the word "hello" after printing the name of each directory and not in the end? ... (1 Reply)
Discussion started by: GeorgeP
1 Replies

Featured Tech Videos