Sponsored Content
Top Forums Shell Programming and Scripting awk print redirection to variable file name Post 302171718 by nazeeb on Friday 29th of February 2008 09:02:30 AM
Old 02-29-2008
Hi krao,

really appreciate your conecern.

the input is just a test file to get the output working on a trial and error basis:

filename: 1
content:
Quote:
1,2,3
4,5,6
7,8,9
i tried so many things (some of which looked funny too):
Code:
nawk -FS=, '{ print $1 > "output_'$2'.txt"}' 1
nawk -FS=, '{ print $1 > "output_\"$2\".txt"}' 1

but it produces output file name with "$" in it.

On the contrary, awk produces the following files:
output_2.txt
output_5.txt
output_8.txt

I think I need a way around to what i am trying to achieve.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print variable in awk

i read the variable ph from file and i wanna to print it in awk. example ph=`cat tmpbatch` tail h.txt|grep "| |"|awk -F"|" '{ print "@unpdx.sql",$5 }'"$ph" i try this but it does not work (8 Replies)
Discussion started by: kazanoova2
8 Replies

2. Shell Programming and Scripting

awk two file redirection

Hi, i use awk -F to print three variable delimited by comma $1 $2 $3 if $2=="" i want to extract this information missing from another file using awk -v + some process. but the problem i can't use the two awk together cause of redirection there's a solution. note: i can't use another... (1 Reply)
Discussion started by: kamel.seg
1 Replies

3. Shell Programming and Scripting

print variable in file using awk

hi, i have store variable in $var i want to print it in $3 of file using awk. how can i do it? file : var1,var2,var3 var5,var6,var7 var8,var9,var10 . . . i want to print $var in $3 ( for example var3 or var7 or var10) thanks (3 Replies)
Discussion started by: kamel.seg
3 Replies

4. Shell Programming and Scripting

How to print a value in the variable using awk ?

:b:Hi All, I have a part of a script below: var1="value1" awk 'BEGIN {printf("%36s \n ","value1")}' Instead of directly giving the "value1" , I need to give using "var1" in the above awk statement. Is this possible? If so, what is the modified awk command? Thanks in advance JS (1 Reply)
Discussion started by: jisha
1 Replies

5. Shell Programming and Scripting

awk output redirection to file

I have a system stat command running which generates data after 5 sec or so. I pass this data to awk and do some calculation to present the data differently. Once done now I want to pass this data to file as and when generated but doesn't work..unless the first command completes successfully.... (6 Replies)
Discussion started by: learnscript
6 Replies

6. Shell Programming and Scripting

awk print variable

I have list of files: ls a.pdf b.pdf c.pdf and so on... and I have a file like this: cat file1 apple mango pear and so on... I want to rename my file like this: (7 Replies)
Discussion started by: zorrox
7 Replies

7. UNIX for Dummies Questions & Answers

little problem of file redirection (awk)

I almost reach my objective (Youhouuu !!!!) But I really don't understand why it doesn't work until the end... :wall: For clarity's sake I am taking a very simple example. The operations I am doing in the script (gsub and print) really don't have any importance !!! I just matter about... (10 Replies)
Discussion started by: beca123456
10 Replies

8. Shell Programming and Scripting

awk print variable then fields in variable

i have this variable: varT="1--2--3--5" i want to use awk to print field 3 from this variable. i dont want to do the "echo $varT". but here's my awk code: awk -v valA="$varT" "BEGIN {print valA}" this prints the entire line. i feel like i'm so close to getting what i want. i... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. Shell Programming and Scripting

awk to lookup stored variable in file and print matching line

The bash bash below extracts the oldest folder from a directory and stores it in filename That result will match a line in bold in input. In the matching line there is an_xxx digit in italics that (once the leading zero is removed) will match a line in link. That is the lint to print in output.... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

awk file redirection issue

So I'm writing a script which tries to parse human-readable addresses. Part of it is this: print $2, implode(A,1,AN," "), CITY, PROV, POST, COUNTRY, CITYCOUNT>2; CITYCOUNT is a variable between 0 and 3 counting the number of words in a city name. I'm trying to prnt 1 wherever that's greater... (5 Replies)
Discussion started by: Corona688
5 Replies
unix2dos(1)						      General Commands Manual						       unix2dos(1)

NAME
unix2dos - UNIX to DOS text file format converter SYNOPSYS
unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents unix2dos, the program that converts text files in UNIX format to DOS format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates unix2dos under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. unix2dos Convert and replace a.txt. Convert and replace b.txt. unix2dos a.txt b.txt unix2dos -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. unix2dos a.txt -c iso b.txt unix2dos -c ascii a.txt -c iso b.txt Convert and replace a.txt while keeping original date stamp. unix2dos -k a.txt unix2dos -k -o a.txt Convert a.txt and write to e.txt. unix2dos -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. unix2dos -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. unix2dos a.txt -n b.txt e.txt unix2dos -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHOR
Benjamin Lin - ( blin@socs.uts.edu.au ) MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
dos2unix(1) 1995.03.31 unix2dos v2.2 unix2dos(1)
All times are GMT -4. The time now is 07:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy