cut the first word in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut the first word in the file
# 1  
Old 07-07-2010
Question cut the first word in the file

how to cut the first word in multiple file at a time

i.e)1st row and 1st colum word in multiple files
# 2  
Old 07-07-2010
If your file is csv:

Code:
awk -F "," '{print $1}' *.csv


change "," with the other character in case its different.
Also your can provide the list of file instead of *.csv

---------- Post updated at 01:50 PM ---------- Previous update was at 01:45 PM ----------

Sorry for not reading the requirement properly.

for first row first field,

Code:
awk -F "," 'NR==1 {print $1}' *.csv

# 3  
Old 07-07-2010
Quote:
Originally Posted by anchal_khare
If your file is csv:

Code:
awk -F "," '{print $1}' *.csv


change "," with the other character in case its different.
Also your can provide the list of file instead of *.csv

---------- Post updated at 01:50 PM ---------- Previous update was at 01:45 PM ----------

Sorry for not reading the requirement properly.

for first row first field,

Code:
awk -F "," 'NR==1 {print $1}' *.csv




its shows some error
HTML Code:
 
awk: syntax error near line 1
awk: bailing out near line 1
let me explain clearly

i have a file called test
content of the file is

HTML Code:
dsd|dfsd|Sdfsdf|sdff
sdfwert|5rygrd|trhyr|dsfsd
edfgsd|aserhtrh|hjfg|


my expected outpu is

HTML Code:
dsd
# 4  
Old 07-07-2010
Code:
# cat infile
dsd|dfsd|Sdfsdf|sdff
sdfwert|5rygrd|trhyr|dsfsd
edfgsd|aserhtrh|hjfg|

Code:
# sed -n '1s/^\([a-z]*\)|.*/\1/p' infile
dsd

This User Gave Thanks to ygemici For This Post:
# 5  
Old 07-07-2010
Code:
awk -F "|" 'NR==1 {print $1}' test

Use nawk or /usr/xpg4/bin/awk on solaris.
This User Gave Thanks to clx For This Post:
# 6  
Old 07-07-2010
thanks team , its working . . .

my next aim is

i have a file called infile


Code:
 
$ cat infile
test.txt
test1.txt
test2.txt

test.txt contain

HTML Code:
asd|asdas|asdas
asd1|asdasrf|sadfsa
sdfwef|rfgdf|dfe
test1.txt contain
HTML Code:
 
wsd|erfe|rtger|ewrf
rgfd|thgfd|gdf|rfgv
dsfsdf|rygdf|hgbdf
test2.txt conatin
HTML Code:
 
qsd|fg|fdgdr
fdgv|fdg|fdtr
trhb|dfs|rfg
my excepted output will be
HTML Code:
 
asd
wsd
qsd
# 7  
Old 07-07-2010
Hi,

Code:
#!/bin/sh

while read filename
do
awk -F "|" 'NR==1 {print $1}' $filename
done < infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Cut a word between two strings and repeat the same in the entire file

in the below data i need to search for the word typeMismatch and then traverse back to find the filename of that particular mismatch. Like this we have to get all the file names which has error in them. How can i acheive this. I tried use sed or awk but not able to achevie the same. Sample... (2 Replies)
Discussion started by: ATWC
2 Replies

2. Shell Programming and Scripting

Cut & Fetch word from string

I have a file with some SQL query, I want to fetch only Table Name from that file line by line. INPUT FILE SELECT * FROM $SCHM.TABLENAME1; ALTER TABLE $SCHM.TABLENAME1 ADD DateOfBirth date; INSERT INTO $SCHM.TABLENAME1 (CustomerName, Country) SELECT SupplierName, Country FROM $SCHM.TABLENAME2... (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

3. UNIX for Advanced & Expert Users

cut words based on the word count of a line

I would like to cut words based on the word count of a line. This over here inspired me with some ideas but I wasn't able to get what I needed. https://www.unix.com/shell-programming-scripting/105841-count-words-each-line-file-using-xargs.html If the line has 6 words I would like to use this.... (8 Replies)
Discussion started by: cokedude
8 Replies

4. UNIX for Advanced & Expert Users

use a word as a delimiter with cut

Is there a way to use a word as a delimiter with cut? Or is there a way to use sed or awk with a word as a delimiter? I don't care which program I use for a delimiter I just want to use a word as a delimiter. (2 Replies)
Discussion started by: cokedude
2 Replies

5. Shell Programming and Scripting

Script to cut the first word in Message Text

Hi, In my shell script, I am connecting to database and querying multiple columns in a table. MESSAGE_TEXT=`sqlplus -s /nolog <<end_log_stmt set heading off set feedback off set verify off set termout off set pages 0 CONNECT APPS/$USER_PWD Select order_number, id, error_message... (6 Replies)
Discussion started by: balajiora
6 Replies

6. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

7. Shell Programming and Scripting

Sed or awk cut all lines after word

Hi, sorry for newbie question :confused: can't find how to cut ? from 1000 2000 word some text1.... 100 200 300 word some text2.... 10 20 30 abc word some text3.... to some text1.... some text2.... some text3.... (7 Replies)
Discussion started by: Trump
7 Replies

8. Shell Programming and Scripting

script to cut a word from the file

hi to all i wrote a script to cut a word from the file....that works only if the word is fixed field. example.. sed -n '1p'|awk '{ print $2 }'|cut -d '(' -f2|sed 's/(//'|sed 's/)//'|sed 's/"//g' filename i know that word is starting with "app" then "(" ----> ex: app("xxxx"). it... (2 Replies)
Discussion started by: honeym210
2 Replies

9. Shell Programming and Scripting

help with cut word

hi there i have this problem , i need cut the 4 first character and the 6 last characters of the word this is my file 'dg_bancdist_logs' 'dg_tibco_logs' 'dg_rmp_logs' 'dg_mig_logs' 'dg_titan_logs' 'dg_swift_logs' 'dg_isis_logs' 'dg_isisges_logs' and i need this ... (4 Replies)
Discussion started by: gonzo
4 Replies

10. Shell Programming and Scripting

cut last line of a word

Hi all, want to delete a crahecter from each line..? how can i do it... (2 Replies)
Discussion started by: bullz26
2 Replies
Login or Register to Ask a Question