Hello,
I need to split a file into two of different locations by re-direction in awk.
The path of the resulted files should be passed in with shell variable, and I have tried:
but none worked with error like: cmd. line:1: (FILENAME=aaa FNR=1) fatal: can't redirect to `awk_var/group_a.gtf' (No such file or directory)
I checked the threads in this forum: How to pass a variable from shell to awk Pass shell Variable to awk
but they did not help me out probably due to my expansion is related to file directory. However, the it worked if the path is hard-coded, which is not thru shell variable along with other part of the shell script.
Also It is interesting with following oneliner, in which the expansion worked at every other hit of ENTER. Could not understand why.
1) What are the rules to expand shell (bash) variables (especialy related to directory) inside awk script?
2) Why my last oneliner worked every other time with ENTER? Thanks a lot!
1) It looks like vgersh99 has already shown you how to expand shell variables for use in awk. Note, however, that his code will append to your two output files; not replace them if they already existed. It also looks like he had a typo looking for "bbb" in field 7 instead of in field 1. And, if you have some value other than "aaa" or "bbb" on an input line, that line will be written to one of those two output files depending on what was on the previous input line or cause awk to error output if another value appeared on the first input line. If that isn't what you want, you might want to try:
The above form should work with any standard awk as long as you don't specify more than 9 output files in your awk script.
2) Your one-liner worked every time you hit ENTER. The blank lines you see in the output are the echo of your input lines and the printing of the contents of your variable is the output from the print statement in your awk script.
This might be more obvious if you used:
These 3 Users Gave Thanks to Don Cragun For This Post:
How can I pass in an argument such as "*.k" to a bash script
without having to double-quote *.k and not having *.k
`glob` to match all files in the pattern?
I tried using noglob in my script but this didn't work the way I thought
it would.. expansion is still occuring, $# is higher than I... (3 Replies)
Hello -
I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER:
MYPID=$$
MYNAME=`basename $0`
LOGGER="/usr/bin/logger -t $MYNAME($LINENO) -p daemon.error"
...
echo 'this is an entry into the log file' | $LOGGER
... (3 Replies)
i write a batch file , here is the content.
dirname='date +%Y-%m-%d'
mkdir dirname
but it doen's work, it just create a folder named date and +%Y-%m-%d.
i have tried run the command seperately in the bash prompt. after the first
sentence executed , i use $dirname to watch the value of... (4 Replies)
This is what I have in my directory.
$ ls
test1.txt test2.txt test3.txt test4.txt test5.txt test_script.sh
This is what my shellscript looks like.
#!/bin/bash
for filename in /shell_expansion/*.txt; do
for ((i=0; i<=3; i++)); do
echo "$filename"
... (5 Replies)
I want to split one file input.tab into two separate ones, odd lines to input_reads1.txt, even lines to input_reads2.txt for a serial of files with similar name pattern. Also I want to "match" input/output file names to keep consistency of file name:
CSEL_02.0_input.tab
CSEL_03.4_input.tab... (2 Replies)
Hello.
I cannot write a command without using eval.
Any help is welcome
Note 1 : What does the function SOMETHING has no importance.
Note 2 : What does the command find has no importance.
It is an expansion variable problem : where to put or or or anythings else
What works (FILTRE_1... (8 Replies)
I have made the following examples that print various parameter expansions
text: iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018.sac
(text%.*): iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018
(text%%.*): iv-hhz-sac/hpac/hhz
(text#*.): d/iv.hpac..hhz.d.2016.250.070018.sac... (2 Replies)
#!/bin/bash
SNMPW='/usr/bin/snmpwalk'
while read h i
do
loc=$($SNMPW -v3 -u 'Myusername' -l authPriv -a SHA -A 'Password1' -x AES -X 'Password2' $i sysLocation.0 2>/dev/null)
loc=${loc:-" is not snmpable."}
loc=${loc##*: }
loc=${loc//,/}
echo "$i,$h,$loc"
done < $1
My question is ... ... (1 Reply)
Hello All,
Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion.
Let's say I have following variable.
path="/var/talend/nat/cdc"
Now to get only nat I could do following.
path1="${path%/*}"
path1="${path1##*/}"
Here... (8 Replies)