Need help in string filtering (KSH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in string filtering (KSH)
# 1  
Old 06-28-2007
Need help in string filtering (KSH)

Hi all,

I'm interested in printing out only the prefix of a formatted set of filenames. All files of this type have the same 8 character suffix. I'm using KSH.

Is there a command I could use to print the filenames, less the last 8 characters? Was thinking of using sed 's/<last 8 chars>//', but this would not take into the case in which the prefix is the same string as the suffix (a rare, but possible case).

Thanks in advance.
# 2  
Old 06-28-2007
Quote:
Originally Posted by rockysfr
Hi all,

I'm interested in printing out only the prefix of a formatted set of filenames. All files of this type have the same 8 character suffix. I'm using KSH.

Is there a command I could use to print the filenames, less the last 8 characters? Was thinking of using sed 's/<last 8 chars>//', but this would not take into the case in which the prefix is the same string as the suffix (a rare, but possible case).

Thanks in advance.
You could do
Code:
sed "s/<last 8 chars>$//"

or

Code:
while read file
do
  echo ${file%????????}
done < list.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to filter string between specific string in ksh

My argument has data as below. 10.9.9.85 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr56scr 127869538 ....... (note all these between lines will start with hyphen '-' ) -rwxr-xr-x user1 2019-10-15 17:40... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Need Help of filtering string from a file.

HI All, We have an Redhat Machine, And some folder with couple simple text files, this files containing a lot of lines with various strings and IP address with different classes. The Requirement in eventually , is to pass the all various IP addresses to Excel. My question is : what is... (4 Replies)
Discussion started by: James Stone
4 Replies

3. Shell Programming and Scripting

Filtering protocol and string in tcpdump command?

Hello to all in forum, Maybe some unix expert could help me. I have the following tcpdump command: tcpdump -i any port 13907 -s 0 -w Out.cap I would like to run tcpdump to only capture data related with especific string. Within the dump the protocol is GSM MAP and the string is Address... (0 Replies)
Discussion started by: cgkmal
0 Replies

4. Shell Programming and Scripting

filtering string

hlow all i need help for my case i want to get variable 20(in bold) but filter in print $3 not $2 so this input 95:20111005_20111123:1821546322 96:20111005_20111123:0053152068 97:20111005_20111123:1820960407 98:20111005_20111123:2021153102 99:20111005_20111123:2021153202... (4 Replies)
Discussion started by: zvtral
4 Replies

5. Shell Programming and Scripting

Replace string in ksh

Hello, I want to locate a special character in each line of a file and replace it with another string that contains a special character and $i (i is incresing each cycle) string1: export IBAN=AAAAAAAAA . . . . export IBAN=zzzzzzzzzzz I want it to be: export IBAN=AAAAAAAAA . export... (1 Reply)
Discussion started by: LiorAmitai
1 Replies

6. Shell Programming and Scripting

filtering out duplicate substrings, regex string from a string

My input contains a single word lines. From each line data.txt prjtestBlaBlatestBlaBla prjthisBlaBlathisBlaBla prjthatBlaBladpthatBlaBla prjgoodBlaBladpgoodBlaBla prjgood1BlaBla123dpgood1BlaBla123 Desired output --> data_out.txt prjtestBlaBla prjthisBlaBla... (8 Replies)
Discussion started by: kchinnam
8 Replies

7. Shell Programming and Scripting

how to copy one string in ksh into another

Hi Does anybody know if there is a utility/command in ksh which would allow to copy/insert the contents of one string into certain positions of the other? for example: A=" ABCDEF " B="HHH" I need to insert contents of string "B" into string "A" from position 3 to 5, so... (3 Replies)
Discussion started by: aoussenko
3 Replies

8. Shell Programming and Scripting

string manipulation in ksh

Hi all, I'm trying to extract the name of a script that is being run with a full path. i.e. if the script name is /some/where/path/script_name.ksh I'd like to extract only: script_name i know that it is possible to do so in two phases: echo "${0##*/}" will give me script_name.ksh and... (4 Replies)
Discussion started by: iceman
4 Replies

9. Shell Programming and Scripting

String length in ksh

Hi all, I have tried the following simple code in ksh. (length.sh) #! /usr/bin/ksh var="xxxxxx0987890" echo stringlength is ${#var} but this gives me a error saying "length.sh: bad substitution" Can some one please help me in resolving this. (4 Replies)
Discussion started by: ssgrpid
4 Replies

10. UNIX for Dummies Questions & Answers

Filtering text from a string

I'm trying to write a script which prints out the users who are loged in. Printing the output of the "users" command isn't the problem. What I want is to filter out my own username. users | grep -v (username) does not work because the whole line in which username exists is suppressed. If... (5 Replies)
Discussion started by: Cozmic
5 Replies
Login or Register to Ask a Question