Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Cut the two column from non delimited file Post 302756111 by Scott on Tuesday 15th of January 2013 08:11:42 AM
Old 01-15-2013
If the fields are separated by a single space, then:
Code:
cut -d" " -f1-2 file

Otherwise it's simple with awk
Code:
awk '{print $1 FS $2}' file

I would add that this kind of question has been asked very many times, and you should search before asking. Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies

2. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

3. Shell Programming and Scripting

How to append database column to a delimited file

Hi, I have the below flat filewith ~ as delimiter emp.no~dept.name I need to append corresponding emp.name column which will come from database based on emp.no in the flat file. I need the output as dept.name~emp.name Can anyone please help me in resolving this issue.. I tried the... (2 Replies)
Discussion started by: siri_886
2 Replies

4. Shell Programming and Scripting

Extract second column tab delimited file

I have a file which looks like this: 73450 articles and news developmental psychology 2006-03-30 16:22:40 1 http://www.usnews.com 73450 articles and news developmental psychology 2006-03-30 16:22:40 2 http://www.apa.org 73450 articles and news developmental psychology 2006-03-30... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

Moving a column across a delimited data file

Hi, I am trying to move a column from one position to another position in a delimited file. The positions are dynamic in nature and are available by environmental variables. Also the file can have n number of columns. Example: Initial Column Position=1 Final Column Position=3 Delimiter='|' ... (2 Replies)
Discussion started by: ayan153
2 Replies

6. Homework & Coursework Questions

how to show particular column from pipe delimited file

hi, I have pipe delimited flat file as below 1|ab|4.5|9| 2|ac|3|12| 3|ac|4.5|8| i want to show (display) only 3rd field between pipes. please help (1 Reply)
Discussion started by: vai15517
1 Replies

7. Shell Programming and Scripting

Append data to first column delimited file

Hi, I have a data like Input: 12||34|56|78 Output: XYZ|12||34|56|78 I tried like this , but it puts it on another line awk -F "|" ' BEGIN {"XYZ"} {print $0} 'file Any quick suggessitons in sed/awk ? am using HP-UX (3 Replies)
Discussion started by: selvankj
3 Replies

8. Shell Programming and Scripting

How to cut a pipe delimited file and paste it with another file to form a comma separated outputfile

Hello ppl I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt Now I have to join (paste in unix) this A2.txt with external file A3.txt to form output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Discussion started by: etldev
25 Replies

9. Shell Programming and Scripting

Replacing a column in a pipe delimited file

Hi, I have a pipe delimited file as below and I need to replace the 2nd column of each line with null values. 1|10/15/2011|fname1|lname1 2|10/15/2012|fname2|lname2 3|10/15/2013|fname3|lname3 Output file: 1||fname1|lname1 2||fname2|lname2 3||fname3|lname3 I tried this ... (2 Replies)
Discussion started by: member2014
2 Replies

10. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies
CUT(1)							      General Commands Manual							    CUT(1)

NAME
cut - select out columns of a file SYNOPSIS
cut [ -b | -c] list [file...] cut -f list [-d delim] [ -s] OPTIONS
-b Cut specified bytes -c Select out specific characters -d Change the column delimiter to delim -f Select out specific fields that are separated by the -i Runs of delimiters count as one -s Suppres lines with no delimiter characters, when used EXAMPLES
cut -f 2 file # Extract field 2 cut -c 1-2,5 file # Extract character columns 1, 2, and 5 cut -c 1-5,7- file # Extract all columns except 6 DESCRIPTION
[file...]" delimiter character ( see delim)" with the -f option. Lines with no delimiters are passwd through untouched" Cut extracts one or more fields or columns from a file and writes them on standard output. If the -f flag is used, the fields are sepa- rated by a delimiter character, normally a tab, but can be changed using the -d flag. If the -c flag is used, specific columns can be specified. The list can be comma or BLANK separated. The -f and -c flags are mutually exclusive. Note: The POSIX1003.2 standard requires the option -b to cut out specific bytes in a file. It is intended for systems with multi byte characters (e.g. kanji), since MINIX uses only one byte characters, this option is equivalent to -c. For the same reason, the option -n has no effect and is not listed in this man- ual page. SEE ALSO
sed(1), awk(9). CUT(1)
All times are GMT -4. The time now is 01:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy