Print column with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print column with awk
# 1  
Old 09-20-2010
Print column with awk

Hi Masters ,

Need your help regarding the below issue .

I am creating a new file with awk where diff rows in a particular column will different according to the user i/p.

If user i/p is 10,11 and 12 and requests for 6 rows then in a particular column will print with
10
10
11
11
12
12

Is it possible ,if yes please let me know.....
Thanks again.
# 2  
Old 09-20-2010
Quote:
Originally Posted by Pratik4891
Hi Masters ,

Need your help regarding the below issue .

I am creating a new file with awk where diff rows in a particular column will different according to the user i/p.

If user i/p is 10,11 and 12 and requests for 6 rows then in a particular column will print with
10
10
11
11
12
12

Is it possible ,if yes please let me know.....
Thanks again.
Yes, it's possible, can you show us what have you tried so far and where you are stuck?

Regards
# 3  
Old 09-20-2010
Hi Franklin ,

Thanks .
So far my code looks like below
Code:
a=RRD3C95AF 
b=C1voice
c=2300300000007310001000420608005900
d=00151430200000
e=+151430200000
f=1150000100000120100612100000
g=55
h=001602383997
i=000999
#echo $a
#echo "$a $b "|nawk '{for(i=1;i<=5;i++){printf("%d\t %d\t\n", $1 , $2)}}' > tempfile.txt
#echo "$a $b $c $d $e $f $g $h "|nawk '{for(i=1;i<=5;i++){printf("%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t\n", $1 , $2 ,$3 ,$4 ,$5 ,$6 ,$7 ,$8)}}' > tempfile.txt
echo HDR2010061219551200000000000Billing Gateway 8.0.3RRD  019068 >  tempfile.txt
echo "$a $b $c $d $e $f $g $h "|nawk '{for(i=1;i<=5;i++){printf("%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t\n", $1 , $2 ,$3 ,$4 ,$5 ,$6 ,$7 ,$8)}}' >> tempfile.txt

but for variable f the first 5 digit should be according to user i/p

Last edited by Franklin52; 09-20-2010 at 07:16 AM.. Reason: Please use code tags, thank you!
# 4  
Old 09-20-2010
Your question is very vague, clarify your question and provide a better example.
# 5  
Old 09-20-2010
Hi
Let me know which part you dont understand

I just want to print values in a column with awk .Now if the column has 10 rows and user i/p is 10 and 20 the for that column first 5 value will be 10 and for next 5 value will be 20.

In my case I am printing vairable f in column 6 .The first 5 digit of variable must be according to user i/p

I am sorry but I dont have any better explanation of my req.
# 6  
Old 09-21-2010
Hi Franklin ,

One another explanation of my query I found out

user i/p 10,20 and number of rows requested by user for each i/p is 3
then o/p
10
10
10
20
20
20
user i/p 10 and number of rows requested by user for each i/p is 2
then o/p
10
10

Can we do this by storing the inputs in array and the printing by executing for loop
Its kind of urgent
Pls help
# 7  
Old 09-21-2010
An example, play around with it and customize it to your taste:
Code:
awk -v n="10,20" -v rows=3 '
BEGIN {
  nnum=split(n,a,",")
  for(i=1;i<=nnum;i++) {
    for(j=1;j<=rows;j++) {
      print a[i]
    }
  }
}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

2. UNIX for Advanced & Expert Users

Help with awk and particular named column print

Hi Unix Gurus, I have some 145+ xml in some folder and I want just loadOperation to be printed. Sample o/p: file1.xml loadOperation="InsertOrUpdate"> file2.xml loadOperation="Update"> file3.xml loadOperation="Update"> file4.xml loadOperation="Append"> In some of them, in the 2nd line,... (3 Replies)
Discussion started by: saps19
3 Replies

3. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

Need to different value print in same column by awk

Hi , i am trying to prepare a text file by awk . My code is like below echo "$a $b $c $d $e $f $g $h "|nawk '{for(i=1;i<=5;i++){printf("%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t\n", $1 , $2 ,$3 ,$4 ,$5 ,$6 ,$7 ,$8)}}' >> tempfile.txt Now my req is $d will print as per user req . if user inputs... (2 Replies)
Discussion started by: Pratik4891
2 Replies

7. Shell Programming and Scripting

find expression with awk in only one column, and if it fits, print whole column

Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column. 1 apple oranges 2 bannanas pears 3 cats dogs 4 hesaid shesaid echo "which number:" read NUMBER (user inputs number 2 for this example) awk " /$NUMBER/ {field to search is field... (2 Replies)
Discussion started by: glev2005
2 Replies

8. Shell Programming and Scripting

Print from second column onwards if $1<=40 using awk

I have a file like below 10 10 21 32 43 54 20 10 25 36 47 58 30 19 20 31 42 53 40 10 24 35 46 57 50 10 28 39 40 51 I need to check if $1 <= 40, then print from $2 onwards. If $1 > 40, the line is not printed. So I would have an output like this 10 21 32 43 54 10 25 36 47... (10 Replies)
Discussion started by: kristinu
10 Replies

9. Shell Programming and Scripting

to print column using awk

suppose u have a file aaaaa aswn 33332 aasdxe sssee 627627 qqhksd dljlljkl 38682682 so have a output 3332 627627 38682682 (2 Replies)
Discussion started by: cdfd123
2 Replies

10. Shell Programming and Scripting

can awk print column using a variable ??

i want to print the column file using awk or cut in dynamic manner like trmp=2;temp1=1;temp3=2 awk 'BEGIN{OFS=IFS="\t"} {print $temp,$temp1,$temp3}' client_data.txt or cut -f $temp1,$temp2,$temp3 -d"\t" file_name . but it is showing error , In awk can i use variable as in printing... (36 Replies)
Discussion started by: jambesh
36 Replies
Login or Register to Ask a Question