How can I find the 3 first letters from the name file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I find the 3 first letters from the name file
# 1  
Old 06-16-2005
How can I find the 3 first letters from the name file

Hello,

I have a name file in Unix for example : ABC_TODAYFirst.001 and I want just capture or display the 3 first letters so : ABC.

I tried with cut -c,1-3 and the name but it displays the 3 first letters of all lines.

Can you help , Thanks a lot
# 2  
Old 06-16-2005
this is confusing..... what does it mean 'it displays the 3 first letters of all lines."?
could you show what you have so far together with sample input and the desired output, pls!
# 3  
Old 06-16-2005
the 3 first letters from the name file

Hello,

Thanks no the problem is I want just display the 3 first letters of the name file.

So for toto.txt , it must display tot

Thanks.
# 4  
Old 06-16-2005
Quote:
Originally Posted by steiner
Hello,

Thanks no the problem is I want just display the 3 first letters of the name file.

So for toto.txt , it must display tot

Thanks.
echo 'toto.txt' | sed 's/^\(...\).*/\1/'
# 5  
Old 06-16-2005
If you mean the first three letters of the files name:

Code:
# filename="abcdefghi"
# print - "${filename%${filename#???}}"
abc

In case you want the first three letters of every line in a given file use sed:

Code:
sed 's/^\(...\).*$/\1/' <filename>

Hope this helps

bakunin
This User Gave Thanks to bakunin For This Post:
# 6  
Old 06-16-2005
i dont speak english well but i think you need es to get the 3 first letters of a list of files right?

like in your first post, if the 4th letter is '_' do this:

Code:
ls -1 | cut -d "_" -f1 > newfile

and you will get what you want in 'newfile' or obmit '> newfile' and you will get what you want in screen.

Lestat
# 7  
Old 06-16-2005
Another thing, i dont understanw well the part of "but it displays the 3 first letters of all lines" that you post, please tell me exactly what kind of files do you have and what exactly you want as output

Lestat
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot find correct syntax to make file name uppercase letters

I have a file name : var=UsrAccChgRpt I want to make them upper case. Tried: $var | tr Error: tr: Invalid combination of options and Strings. Usage: tr | -ds | -s | -ds | -s ] String1 String2 tr { -d | -s | -d | -s } String1 Could you please help. I am using AIX... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Find words containing small letters

Hello, I have a file containing different words. How can i print the words which contain at least one small letter, for example if i have: today TOMORROw 12345 123a next preViou5 no it should print the following: today TOMORROw 123a next preViou5 no Please use code tags as required... (5 Replies)
Discussion started by: JhonTheNewbie
5 Replies

3. UNIX for Beginners Questions & Answers

Listing a file/directory with 7 letters long

I know that I can use wild cards:ls ???????to list files 7 characters long, but how do i omit the .?! and spaces? Please use CODE tags when displaying sample input, sample output, and code segments. (2 Replies)
Discussion started by: hiya54
2 Replies

4. UNIX for Dummies Questions & Answers

Find & Replace with same case letters

I have text with upper and lower case words. I want to find something and replace it with something new. But it should match the case - Meaning - it should replace old upper cased word with NEW upper case word and lower with lower. example: this text is very simple TEXT. now I want to replace... (5 Replies)
Discussion started by: grep_me
5 Replies

5. Shell Programming and Scripting

Grep/Awk on 1st 2 Letters in 2nd Column of File

Hi everyone. I need to change a script (ksh) so that it will grep on the 1st 2 letters in the second column of a 5 column file such as this one: 192.168.1.1 CAXY0_123 10ABFL000001 # Comment 192.168.1.2 CAYZ0_123 10ABTX000002 # Comment 192.168.2.1 FLXY0_123 11ABCA000001 ... (4 Replies)
Discussion started by: TheNovice
4 Replies

6. Shell Programming and Scripting

Find and arrange words with same letters from list

I am making a word game and I am wondering how to find and arrange words in a list that have the same letters. In my game, you are presented with 5 letters, and you then have to rearrange the letters tp make a word. So the word could be "acorn", but those 5 letters could also make up "narco" or... (2 Replies)
Discussion started by: hellobard
2 Replies

7. Shell Programming and Scripting

Trying to find number of uppercase and lowercase letters.

Hello Guys, I am writing a script which check each line for how many Uppercase and Lowercase letter of a given file. Please check my script as follow: l=0 while read line do echo Line `expr $l + 1` has ` tr -cd "" < $line | wc -c` uppercase letters and `tr -cd "" < $line | wc -c`... (3 Replies)
Discussion started by: kasparov
3 Replies

8. Shell Programming and Scripting

changing all characters of a file to capital letters

Hi guys. I have file named output.txt containing file names. one per line. I use this command to convert all characters to capital letters and write to the same file. cat output.txt | tr 'a-z' 'A-Z' > output.txtBut at the end output.txt is emtpy. Could anyone help?? (6 Replies)
Discussion started by: majid.merkava
6 Replies

9. UNIX for Dummies Questions & Answers

Searching for three or four Uppercase Letters within a file

Looking how to find only three or four letter strings using grep in a file called hello: file contains: TIT TAT RATA ERAT RATE HI RE CA PA CHANGE SANDY ANSWER I am using the code: (4 Replies)
Discussion started by: auerbeck.tyler
4 Replies

10. UNIX for Advanced & Expert Users

look in file, seperate letters, put in order...

okay, I need some help! Im trying to write a script where it looks in the file you designate, pulls apart all the words so i can count how many of each letter there is in the file, then i need to put them in the order of the most occuring letter to the least. This most likley will need a loop... (3 Replies)
Discussion started by: chekeitout
3 Replies
Login or Register to Ask a Question