In a shell script I am writing I execute this command:
uniq -c names1.tmp > names2.tmp
In names2.tmp I get these results:
4 user
2 username
1 users
1 veriano
1 victoria
I need to isolate the names in this file and put it in another file. However it seems that the number and name are considered one field, f7 so I cannot seem to use the cut command to get the names. Any ideas on how I can do so?
It's not working. I get nothing. The only difference here is you declared the delimiter before the field but the result is the same.... I have cut and paste the file I need to work on below. As you can see there is a huge tab. For some reason the number and name are considered field 7. When I cut f 7 I get the number and name. I hope someone can help me solve this strange problem.
1 Aaliyah
1 Aaron
1 Aba
1 Abel
1 Amanda
1 Andrew
1 Ashley
1 Beavis
1 Buster
1 Cowboys
1 Dakota
1 Dallas
1 Dolphin
1 Friends
1 George
1 Hatton
1 Hockey
1 Internet
1 Jessica
1 Jewel
1 Jordan
1 Justin
2 Maddock
I am using the following:
# cut --version
cut (coreutils) 5.0
Written by David Ihnat, David MacKenzie, and Jim Meyering.
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I can't see any tabs. Check your post. You can post code and logs etc. inside [ code ] and [ /code ] tags so most formatting won't get list.
Also by what you present as input, I can't see any field number 7. All I see is 2 fields per row, considering the space is the field separator.
Try to post your input and desired ouput with all field and tabs etc. so we can give a working example.
Without seeing your real input/desired output, you could check to extract the wanted fields maybe with awk, assuming that the field separator is any kind of blank/space/tab and that you have at least 7 fields per row/line:
1 Aaliyah
1 Aaron
1 Aba
1 Abel
1 Amanda
1 Andrew
1 Ashley
1 Beavis
1 Buster
1 Cowboys
1 Dakota
1 Dallas
1 Dolphin
1 Friends
1 George
1 Hatton
1 Hockey
1 Internet
1 Jessica
1 Jewel
1 Jordan
1 Justin
2 Maddock
So you see there is a large indent on the left. When I execute the cut command command on f2 I get nothing. When I execute on f7 I get the following which is weird:
1 Abel
1 Amanda
1 Andrew
1 Ashley
1 Beavis
1 Buster
1 Cowboys
1 Dakota
1 Dallas
1 Dolphin
1 Friends
1 George
1 Hatton
1 Hockey
1 Internet
1 Jessica
1 Jewel
1 Jordan
1 Justin
2 Maddock
Do you want to know something weird? I left out the -d option for delimiter and I ran
cut -f2 names2.tmp ...guess what? I got the right answer:
undead
unix
up
upload
user
username
users
veriano
victoria
walter
wayne
web
webadm
webadmin
webdev
webmaster
webpop
welcome
wheeling
willow
wizard
www
www-data
> cat file67
joe
joe
joe
henry
henry
isabelle
monique
monique
nicole
nicole
nicole
nicole
> sort file67 | sed "s/^/,/" | uniq -c
2 ,henry
1 ,isabelle
3 ,joe
2 ,monique
4 ,nicole
A couple of good things come out of this:
(1) there is now a comma between fields to allow easier extraction
(2) the output, if saved to a file, can be opened by Excel as a csv file