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?
# 8  
Old 06-30-2016
sorry it should be from right to left. I stand corrected.

Thanks to you sir.
# 9  
Old 06-30-2016
Assuming that you're using a shell that performs basic POSIX-required parameter expansions, Scrutinizer already gave you two ways to do what you want in post #6 in this thread.

If you aren't using a POSIX-conforming shell, you need to answer the questions I raised in post #7 in this thread so we can help you find something that will work in your environment.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 06-30-2016
Hi Scrutinizer,

Thanks this works for me.

Code:
echo "${foo#"${foo%???????}"}"


Last edited by Scrutinizer; 06-30-2016 at 03:42 AM.. Reason: forgot to include the script; [mod] code tags
# 11  
Old 06-30-2016
You are welcome, in bash, ksh93 and zsh you can also do this:
Code:
echo "${foo: -7}"

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