Help with awk printout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk printout
# 1  
Old 11-03-2008
Help with awk printout

I want to represent the columns by whats in a txt file. So the columns.txt file contains "$2$3" and the test.txt file contains "bob tom jones jon"

I have
Code:
#!/bin/bash

columnsVar=`cat columns.txt`
echo "Columns edited: $columnsVar"

awk ' {print $columnsVar }' test.txt

But it prints out all the columns.

Also, something like this just gives me an error

Code:
awk ' {print `cat columns.txt` }'

Any suggestions?
# 2  
Old 11-03-2008
I could suggest a solution using cut. If you change the file columns.txt to look something like "2,3", or if the format is fixed you could consider reformating "$2$3" to "2,3".

so then

> echo "columnsVar"
2,3

> cut -d' ' -f$columnsVar test.txt
tom jones

I hope this is what you're looking for...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk --> selective printout with FNR

Hi everybody! need some awk-support. i want a line-selective printout of a file. wat i normally will do with ... awk ' FNR==8' sample.txt But now i need the data from line 8, 10 and the following data from line13 to 250 wich is not end of the file. I tried allready to combine it but without... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

3. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Debian

hardware printout layout terminology

trying to find online or a book. the words to use to find 'a' or 'the ways and means' to format left margin, right margin etc from man pages to Hardware Printer. while looking to print man pages with a Hardware Printer. I have found lp. and did a man sudoers | lp -p2 to test. The... (1 Reply)
Discussion started by: cowLips
1 Replies

7. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

8. Shell Programming and Scripting

sqlplus: could it be dirrected do not printout anything, beside results?

I try to prepare a sufficient function to execute a sql-statement, getting back ONLY retrieved results! What I can't figured out how to make the sqlplus not printing the 'Connected to ...', 'Disconnected from...' and the executed statements after 'SQL> '. I am under impression that having... (5 Replies)
Discussion started by: alex_5161
5 Replies

9. SCO

How to remove date and page header from a printout

I have some HP4+ and HP5 printers printing from Unixware 7.1.4. The problem is that they print a page header with the date and page number. I can't seem to figure out how to stop this. These headers through the pagination off. (2 Replies)
Discussion started by: sladeburke
2 Replies

10. Red Hat

How to take printout of linux file from windows xp using putty?

Friends, I have installed Putty in my windows xp pc. I am connecting the RHEL AS 3 server using putty from my windows xp. My printer is connected to my windows xp. Now, i want to print text.txt of RHEL AS 3.0 in my windows xp printer through putty. For Example: my pc ip is 117.23.2.55... (3 Replies)
Discussion started by: sathyguy
3 Replies
Login or Register to Ask a Question