Extracting directory portion.

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extracting directory portion.
# 1  
Old 03-04-2018
Extracting directory portion.

Dear Experts,

I have some directory structure something like follows. I would like to cut portion of it. Would you please help me? I have to run this on several sql's. The directory path is dynamic. I have cut what comes after first "sql" string.

Input:
Code:
/opt/fedex/acqulev1/abinitio/acqu/private_sand/legacy_acquisition/sql/DELETE/FCIS/delete_CS53_2.sql

Output:
Code:
/DELETE/FCIS/delete_CS53_2.sql

I have to do reverse of below sed.

Code:
sed 's/sql.*//'

# 2  
Old 03-04-2018
How / where is that string stored, in a variable? A file? A DB table?
# 3  
Old 03-07-2018
Quote:
Originally Posted by srikanth38
Dear Experts,

I have some directory structure something like follows. I would like to cut portion of it. Would you please help me? I have to run this on several sql's. The directory path is dynamic. I have cut what comes after first "sql" string.

Input:
Code:
/opt/fedex/acqulev1/abinitio/acqu/private_sand/legacy_acquisition/sql/DELETE/FCIS/delete_CS53_2.sql

Output:
Code:
/DELETE/FCIS/delete_CS53_2.sql

I have to do reverse of below sed.

Code:
sed 's/sql.*//'

I have got the answer, just used different delimiter.

Code:
echo /opt/fedex/acqulev1/abinitio/acqu/private_sand/legacy_acquisition/sql/DELETE/FCIS/delete_CS53_2.sql|sed 's|'$AI_SQL'||'

# 4  
Old 03-08-2018
Consider the following, done without any external program:
Code:
fullpath='/opt/fedex/acqulev1/abinitio/acqu/private_sand/legacy_acquisition/sql/DELETE/FCIS/delete_CS53_2.sql'
pivot="sql"
remove=${fullpath#*$pivot}
echo ${fullpath%$remove}

Output:
Code:
/opt/fedex/acqulev1/abinitio/acqu/private_sand/legacy_acquisition/sql

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to add portion of text to files in directory using numerical match

In the below bash I am trying to rename eachof the 3 text files in /home/cmccabe/Desktop/percent by matching the numerical portion of each file to lines 3,4, or 5 in /home/cmccabe/Desktop/analysis.txt. There will always be a match between the files. When a match is found each text file in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. UNIX for Beginners Questions & Answers

Extracting to another directory using cygwin

I have a file, in Windows, called php_0.27.tar.gz and want to extract it to C:\Program Files\PHP\script through Cygwin using this command: tar -xf php_0.27.tar.gz -C /Program Files/PHP/script But I got an error saying: tar: Files: Not found in archive I tried this command too: ... (8 Replies)
Discussion started by: steve120
8 Replies

3. Shell Programming and Scripting

Extracting a portion of the filename

Hi I would like to extract the first portion of filename from a list of files. The filename pattern is of the form 123456789_TEXT_TEXT_TEXT_.csv. I want to extract just the numerical portion of this filename from the list of files and then output this into another text file. K (6 Replies)
Discussion started by: kamal_p_99
6 Replies

4. Shell Programming and Scripting

Extracting into a remote directory

I need to fit in a module in my Korn Shell script which would extract file_archive.tar.gz residing in the folder /apps/Test of my local machine into a folder /global/ in a remote machine server1. Please help me on this regard. Thanks Kumarjit. (2 Replies)
Discussion started by: kumarjt
2 Replies

5. Shell Programming and Scripting

Zipping a directory and extracting to another server.

Hello everyone, I am trying to make a script in KSH that will zip an entire directory but leave out one file in that directory. I then need to send that zipped directory to another UNIX box. I am new to UNIX and would appreciate a good template to study from. (3 Replies)
Discussion started by: BrutalBryan
3 Replies

6. Shell Programming and Scripting

Extracting a portion of the string and comparing

I have 2 text files say file1.txt and file2.txt . Some of the sample records for file1.txt were shown below: XXXXX12345XXXXXXX12 3456789YYYYY XXXXXXXXXX12345XX123457485YYYYY XX12345XXXXXXXXXX123454658YYYYY for file2.txt, some of the sample records were shown below: ... (5 Replies)
Discussion started by: bobby1015
5 Replies

7. Shell Programming and Scripting

Extracting Directory From Path

Hi guys. I'm doing some bash scripting and have run into a snag. Say I have the path: /home/one/two/three/ All I need is the 'three' while making a filename. Is there an easy way to do this? I've tried using grep (because I'm that smart.) cut (as I'm unable to tell how many fields there... (3 Replies)
Discussion started by: Drayol
3 Replies

8. Shell Programming and Scripting

Help on extracting portion of string

Hi Gurus, I've some sample of my log information as shown below. -> Processing ABCD123456 This is tp version 372.04.57 (release 700, unicode enabled) This is R3trans version 6.14 (release 700 - 05.03.09 - 08:28:00). unicode enabled version R3trans finished (0000). Warning: Parameter... (1 Reply)
Discussion started by: superHonda123
1 Replies

9. Shell Programming and Scripting

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

10. Shell Programming and Scripting

Extracting a portion of a data file with identifier

Hi, I do have a TAB delimted text file with the following format. 1 (- identifier of each group. this text is not present in the file only number) 1 3 4 65 56 WERTF 2 3 4 56 56 GHTYHU 3 3 5 64 23 VMFKLG 2 1 3 4 65 56 DGTEYDH 2 3 4 56 56 FJJJCKC 3 3 5 64 23 FNNNCHD 3 1 3 4 65 56 JDHJDH... (9 Replies)
Discussion started by: Lucky Ali
9 Replies
Login or Register to Ask a Question