Sponsored Content
Full Discussion: extract column with awk
Top Forums Shell Programming and Scripting extract column with awk Post 302705253 by xshang on Monday 24th of September 2012 01:08:10 PM
Old 09-24-2012
Sorry, I can't express clearly what I mean.

The txt file could be understand like this:

ID CDR1 CDR2 CDR3
1 CDR1 NULL CDR3
2 CDR1 CDR2 CDR3
3 NULL NULL CDR3

The results I want to get should be four "CDR3". "NULL" here represents blank space, so maybe I should deal with the original file?

Thanks a lot!

Quote:
Originally Posted by in2nix4life
Code:
cat file

ID CDR1 CDR2 CDR3
1 CDR1   CDR3
2 CDR1 CDR2 CDR3
3     CDR3

awk '$4 == ""{$4="NULL"}{print $4}' file

CDR3
NULL
CDR3
NULL

---------- Post updated at 12:08 PM ---------- Previous update was at 11:50 AM ----------

Sorry, I can't express clearly what I mean. I use space as the separator.

The txt file could be understand like this:

ID CDR1 CDR2 CDR3
1 CDR1 NULL CDR3
2 CDR1 CDR2 CDR3
3 NULL NULL CDR3

The results I want to get should be four "CDR3". "NULL" here represents blank space, so maybe I should deal with the original file?

Thanks a lot!

Quote:
Originally Posted by Corona688
What separator is used in your text file? Tab, space?

You might be able to tell it to use a single space or tab as the separator rather than globbing all whitespace...

Code:
awk -F"\t" '{ print $1,$4 }'
awk -F" " '{ print $1,$4 }'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract a column from two different files in AWK?

Hi guys, I need help in extracting one column of numbers from two different files and display it in a output file. In specific, I want to extrac the column no.2 ($2) from each file, file1.txt, file2.txt. Then place both extracted columns in a one file, out.txt. the line command I use to... (7 Replies)
Discussion started by: solracq
7 Replies

2. Shell Programming and Scripting

awk/sed to extract column bases on partial match

Hi I have a log file which has outputs like the one below conn=24,196 op=1 RESULT err=0 tag=0 nentries=9 etime=3,712 dbtime=0 mem=486,183,328/2,147,483,648 Now most of the time I am only interested in the time ( the first column) and a column that begins with etime i.e... (8 Replies)
Discussion started by: pkabali
8 Replies

3. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

4. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

5. Shell Programming and Scripting

Compare files & extract column awk

I have two tab delimited files as given below: File_1: PV16 E1 865 2814 1950 PV16 E2 2756 3853 1098 PV16 E4 3333 3620 288 PV16 E5 3850 4101 252 PV16 E6 83 559 477 PV16 E7 562 858 297 PV16 L2 4237 5658 ... (10 Replies)
Discussion started by: vaibhavvsk
10 Replies

6. UNIX for Dummies Questions & Answers

awk - Extract 4 lines in Column to Rows Tab Delimited between tags

I have tried the following to no avail. xargs -n8 < test.txt awk '{if(NR%6!=0){p=""}else{p="\n"};printf $0" "p}' Mod_Alm_log.txt > test.txt I have tried different variations of the above, the problem is mixes lines together. And it includes the tags "%a and %A" I need them to be all tab... (16 Replies)
Discussion started by: mytouchsr
16 Replies

7. 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

8. Shell Programming and Scripting

awk to extract value from column using variable

I am having trouble extracting the value in the columns declared in a variable. I have tried several different variation of awk but both give me the column number and not the actual value of that column. Any suggestions? Neither of the "extract" variables below are performing as desired ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

9. Shell Programming and Scripting

Get extract and replace column with link in a column where it exists

hi i have sample data a,b,c,d,e,g h http://mysite.xyx z,b,d,f,e,s t http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing output expected is a,b,c,d,e,http://mysite.xyx z,b,d,f,e,http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing i can get only links using grep -o 'http.*' i... (8 Replies)
Discussion started by: zozoo
8 Replies

10. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies
memalign(3C)															      memalign(3C)

NAME
memalign() - allocate aligned memory SYNOPSIS
DESCRIPTION
allocates space for a block of size bytes, whose address is a multiple of boundary. The space is not initialized. The boundary must be a power of 2. EXTERNAL INFLUENCES
employs the allocator. For tuning information, see the malloc(3C) man page. RETURN VALUE
Upon successful completion, returns a pointer to space aligned to a multiple of boundary. Otherwise, it returns a NULL pointer. DIAGNOSTICS
returns a NULL pointer if there is no available memory, or if the value of boundary is not a power of 2. ERRORS
sets to and returns a NULL pointer when an out-of-memory condition arises. sets to and returns a NULL pointer when the value of boundary is not a power of 2. sets to and returns a NULL pointer when the memory being managed by has been detectably corrupted. WARNINGS
For warnings, see the malloc(3C) man page. SEE ALSO
thread_safety(5). STANDARDS CONFORMANCE
There appear to be no standards applicable to Some implementations do not check that boundary is a power of 2. The HP-UX implementation is not derived from any predecessor. memalign(3C)
All times are GMT -4. The time now is 06:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy