Defining variable problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Defining variable problem
# 8  
Old 07-15-2014
Code:
awk -v value="$value" 'NR==7{$0=$0" "value}1' input > /tmp/output
mv /tmp/output input

-v - define variable for awk
value=$value - value is a variable name which holds the value of $value. For understanding purpose, make it as v=$value # v is the variable which holds the value of $value

NR = give the number of records being processed.
NR==7 when awk reads the 7th line, we are changing the 7th line value as "7th line value + $value" and for printing all the lines i added 1 in the end. which is equivalent of {print}
This User Gave Thanks to itkamaraj For This Post:
# 9  
Old 07-15-2014
Awesome man! Thanks! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Problem defining a struct

I have the following code and getting the compilation errors baseLib/DynBaseObj.h:80: error: expected constructor, destructor, or type conversion before ‘(' token baseLib/DynBaseObj.h:89: error: expected constructor, destructor, or type conversion before ‘(' token baseLib/DynBaseObj.h:101:... (0 Replies)
Discussion started by: kristinu
0 Replies

2. UNIX for Dummies Questions & Answers

defining variable in .profile

In root dir i have created a .profile file and added variable and assigned a path to it: a = '/dir/dir' export a but when i echo (echo $a) the path or use this variable the value or path not getting displayed. i tried executing the .profile and logging out and logging in, didnt workout. am... (1 Reply)
Discussion started by: abhi_n123
1 Replies

3. Shell Programming and Scripting

alias defining problem in .cshrc file

Hi folks, I'm trying to define the following command as alias in .cshrc file: ls -ltr | grep ^d | awk '{print $9}' | xargs du -hs I defined it as the following: alias nirdirs '`ls -ltr | grep "^d" | awk "{print \\$9}" | xargs du -hs`' I've got the following error when I've run the alias:... (7 Replies)
Discussion started by: nir_s
7 Replies

4. Shell Programming and Scripting

defining a variable using multiple "entries/columns" within a line using read

Hello All, I am trying to figure out how to use the read command. I have a txt file that has rows looking something like this: 1 2 3 4 5 6 7 8 9 where each number represents an entry of various characters deliminated by tabs. My goal is to set entries 2-7 as a variable/string that I... (3 Replies)
Discussion started by: Torinator
3 Replies

5. Shell Programming and Scripting

defining variables

Hey all, I was wondering if someone would take a look at this script I'm working on. I don't know if i have the syntax correct for my variables and if the for loop is written correctly. any assistance would be greatly appreciated. #!/usr/bin/bash ###########################################... (12 Replies)
Discussion started by: em23
12 Replies

6. UNIX for Dummies Questions & Answers

Defining EDITOR Variable - Tru64

Hi, I have to edit a lot of partitions soon and wanted to do so with EMACS rather than VI. The "disklabel -e -r disknumber" command picks up VI as it's defined, but how do I set "-e" so it uses EMACS instead please? Thanks...! (2 Replies)
Discussion started by: Bagel08
2 Replies

7. Solaris

Problem defining remote printers on solaris 10

Good morning, I have a server with solaris 10 that I want to intall remote printers. I started lpsched deamon without problems with command: svcadm enable application/print/server I want to install printers that are defined locally on print server, so: lpadmin -p <device> -s <print... (2 Replies)
Discussion started by: bonovox
2 Replies

8. Shell Programming and Scripting

Sorting/Filed Defining/Output problem

need a little help with a few tid bits. I wrote a script that checks the resoluion of image files and writes them out to a file then sorts the resolutions by largets Width. Then take the sorted files information and toss all the 835 widths into a seperate file. Ignore the redundancies its a... (1 Reply)
Discussion started by: TiredOrangeCat
1 Replies

9. UNIX for Dummies Questions & Answers

Defining Variables

I'm trying to define a variable named sin I already have a variable named cos, which has the value "hello" I want sin to have the value of "hellothere", so sin would be something like sin = $cos & "there" but I'm not sure that I know the syntax. Can anyone help? :confused: (4 Replies)
Discussion started by: sailorliones
4 Replies

10. UNIX for Dummies Questions & Answers

defining a variable as a number or character?

I am writing a script that needs to accept numbers into a variable by prompting and using the code read num case $num in 000) break ;; *) I am fairly new to unix and am loving the versatility of the language but need a little shove in the right... (1 Reply)
Discussion started by: noobian
1 Replies
Login or Register to Ask a Question