Use cut output as variable piped awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use cut output as variable piped awk command
# 1  
Old 06-23-2018
Use cut output as variable piped awk command

Hi,

I would like use the output of my cut command as a variable in my following awk command. Here's what I've written.

Code:
cut -f1 info.txt | awk -v i=xargs -F'[\t]' '{if($6 == $i) print $20}' summary.txt

Where obviously the 'xargs' doesn't do what I want. How can I pass my cut result to my awk statement. I'm trying to avoid writing a shell script. There must be a way to do this. Maybe the varaible is represented by somesort of builtin variable???

Thanks!
# 2  
Old 06-24-2018
Showing us a command that does not work without explaining what you do want gives us no information that we can use to figure out what is going wrong.

But, since the default field separator for cut is a <tab> character and you're only extracting the first input field from info.txt to be fed into your awk script, it is obvious that the 6th and 20th fields in the input that awk is reading will ALWAYS be empty strings. And, since the string xargs is not a numeric string, the string specified by $i will either be treated as a synonym for $0 or treated as a syntax error. (And, since you haven't bothered to tell us what operating system or shell you're using, there isn't any way that we can test what might happen on your system!)

If you'd like to give us a sample input file, a specification of what you're trying to accomplish, the output that you hope to produce from your sample input file, and tell us what operating system and shell you're using, we might be able to help you accomplish your goal.

Oops! I take it back. Since you're giving awk the name of a file to process, the cut command output will be completely ignore by awk.

Last edited by Don Cragun; 06-24-2018 at 12:43 AM.. Reason: Add update.
# 3  
Old 06-24-2018
Geez nevermind.

Geez nevermind. I thought the command was simple enough.
# 4  
Old 06-24-2018
Yes. You have two simple commands connected into a single pipeline that clearly is not doing what you intended it to do.

Given that only you know what it is that you're trying to do and the pipeline you're using is not doing that, why is it so unreasonable for me to ask you to tell us what you are trying to do?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Results of ldapsearch piped to grep are cut off

ldapsearch -x -LLL -E pr=200/noprompt -h abc-loc.somecompany.com -D "account@somecompany.com" -w password -b "cn=groupname,ou=Resource,ou=groups,dc=abc,dc=somecompany,dc=com" | grep member Results are: member: CN=Hanson\, Joe,OU=End Users,OU=Accounts,DC=abc,DC=somecompany,DC=com member:... (3 Replies)
Discussion started by: who10
3 Replies

2. Shell Programming and Scripting

Storing command output in a variable and using cut/awk

Hi, My aim is to get the md5 hash of a file and store it in a variable. var1="md5sum file1" $var1 The above outputs fine but also contains the filename, so somthing like this 243ASsf25 file1 i just need to get the first part and put it into a variable. var1="md5sum file1"... (5 Replies)
Discussion started by: JustALol
5 Replies

3. UNIX for Dummies Questions & Answers

Tcsh command for assigning output of awk to variable

Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files. So if the textfile is data.txt with 2 values x and y I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been... (6 Replies)
Discussion started by: violin
6 Replies

4. Shell Programming and Scripting

sed and cut command in variable

hi, i want to remove 12 and 13 column from psv files and dump them in new folder ls -ltr *GTDA_Dly_Pmix_*.psv>filename.xls var1=`cat filename.xls` for i in $var1 do var3=`echo "$i" |cut -d '|' -f12,13 |sort -u` sed -e 's/"|$var3"//g... (2 Replies)
Discussion started by: renuk
2 Replies

5. Shell Programming and Scripting

Assinging output of cut command

Hi, I have the files in the following files in a folder 19996587342 19487656550 19534838736 And i need to get the first 6 characters from the abvoe files so i used the following script #!/bin/ksh for i in 19* do txt= `$i | cut -c -6` echo "$txt" done The error is at... (4 Replies)
Discussion started by: smile689
4 Replies

6. UNIX for Dummies Questions & Answers

Finding the modified timestamp of files from the piped output of du command

Version Info +++++++++++++++ RHEL 5.4 Since ls command lists file sizes in Bytes which can be long I use du command like below. I have run the du command for the below files as shown below. But I want pipe this output to ls command just to see the modified timestamp for these files. ... (7 Replies)
Discussion started by: kraljic
7 Replies

7. Shell Programming and Scripting

Can't Output Piped Perl In-line command to a File

Hello, I'm pretty stumped, and I don't know why I am not able to redirect the output to the 'graphme' file with the command below in Fedora 18. tcpdump -l -n -t "tcp == 18" | perl -ane '($s,$j)=split(/,/,$F,2); print "$s\n";' > graphme In case you're wondering, I was following the example... (2 Replies)
Discussion started by: ConcealedKnight
2 Replies

8. Shell Programming and Scripting

Output piped to case insensitive awk

I have an encrypted password file, and I've created a simple script to search the password file for a particular record. There are multiple lines per record, so I'm using a record delimiter. #!/bin/bash PATTERN=$1 openssl des3 -d -salt -in ~/docs/pass.des3 | awk '{ FS="\n" ; RS="*" }... (2 Replies)
Discussion started by: 0rac1e
2 Replies

9. Shell Programming and Scripting

storing output from echo & cut into variable

Hi All, Hope someone can advise here as I have been struggling to find a syntax that works here. I have tried a stack of combination I have seed in the forums but I think because I have needed to use "" and `` in the statments another method is found. I am reading in lines with the following... (1 Reply)
Discussion started by: nkwilliams
1 Replies

10. UNIX for Dummies Questions & Answers

How can I cut output of command??

I am on a Linux system using bash shell. I only want to see the number in the Use% field as the output. #df -h / Filesystem Size Used Avail Use% Mounted on /dev/dasda1 2.3G 2.1G 51M 98% / !#/bin/bash df -h / | awk '{print $5}' | cut -c1-2 Us 98 How do... (2 Replies)
Discussion started by: darthur
2 Replies
Login or Register to Ask a Question