How to print 7 chars from left of filemane?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to print 7 chars from left of filemane?
# 1  
Old 06-29-2016
How to print 7 chars from left of filemane?

Hi Guys

Kindly help me on my predicament. I want to get the 7 chars of this filename



I need to get the ALL.cmd from this filehame filename_a_ALL.cmd

Thanks
# 2  
Old 06-29-2016
That file name is in a
- shell variable
- program variable
- (text) file
?
# 3  
Old 06-29-2016
the value will be coming from for loop
# 4  
Old 06-29-2016
In a shell variable?
# 5  
Old 06-29-2016
yes it is..

thanks a lot Smilie
# 6  
Old 06-29-2016
Try this if you want to use the underscore as separator:
Code:
foo=filename_a_ALL.cmd
echo "${foo##*_}"

Or, if it really needs to be the last 7 characters:
Code:
echo "${foo#"${foo%???????}"}"

# 7  
Old 06-29-2016
What shell are you using (and what version of that shell)?

What operating system are you using?

Wouldn't "7 chars from left of filemane(sic)" when the filename is filename_a_ALL.cmd be filenam instead of ALL.cmd?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. Shell Programming and Scripting

sed - print only the chars that match a given set in a string

For a given string that may contain any ASCII chars, i.e. that matches .*, find and print only the chars that are in a given subset. The string could also have numbers, uppercase, special chars such as ~!@#$%^&*(){}\", whatever a user could type in without going esoteric For simplicity take... (1 Reply)
Discussion started by: naderra
1 Replies

3. AIX

How much resources is left on the P7?

I know that it is possible to login into the HMC console and view all the specs like, how much CPU/RAM every LPAR has. But how can I check how much the whole P7 has in total and how much is left to creat a new LPAR:wall: (5 Replies)
Discussion started by: DiViN3
5 Replies

4. Shell Programming and Scripting

Find Special/Null/Control Chars and Print Line Numbers

Hi All, This might be a basic question... I need to write a script to find all/any Speacial/Null/Control Chars and Print Line Numbers from an input file. Output something like Null Characters in File Name at : Line Numbers Line = Print the line Control Characters in File Name at : Line... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies

5. Shell Programming and Scripting

print all between patterns with special chars

Hi, I'm having trouble with awk print all characters between 2 patterns. I tried more then one solution found on this forum but with no success. Probably my mistakes are due to the special characters "" and "]"in the search patterns. Well, have a log file like this: logfile.txt ... (3 Replies)
Discussion started by: ginolatino
3 Replies

6. Shell Programming and Scripting

[Solved] print chars of a string

how can i print all the chars of a string one by line? i have thought that use a for cicle and use this command inside: ${VARIABLE:0:last}but how can i make last? because string is random P.S. VARIABLE is the string or can i make a variable for every chars of this string? this was my idea... (10 Replies)
Discussion started by: tafazzi87
10 Replies

7. Shell Programming and Scripting

awk to print count for chars recurrence

input: 123456 1111 124567 2222 125678 3333 234567 aaaa 456789 abcd awk logic: - read lines for recurring 1st 2 chars of the 1st field - if recurrence detected count up and print value output: 1 123456 1111 2 124567 2222 3 125678 3333 (6 Replies)
Discussion started by: ux4me
6 Replies

8. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

9. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies

10. Shell Programming and Scripting

what left of the pattern

I have a script which loop through a directory then report any file matches the given pattern, say, the pattern is "a2006", this file would be returned a20061101.txt I would like to know how can I get the remaining of the filename, so a20061101txt - a2006 = 1101.txt Can anybody help? Thank... (2 Replies)
Discussion started by: mpang_
2 Replies
Login or Register to Ask a Question