Sponsored Content
Top Forums Shell Programming and Scripting extract string portion from filename using sed Post 302318833 by fpmurphy on Friday 22nd of May 2009 11:33:43 AM
Old 05-22-2009
BTW, there is no need to invoke sed to parse the filename. It can all be done within bash i.e.
Code:
$ fname="TOP_TABIN240_20090323.200903231830"
$ source_file_issue_date=$(tmp=${fname/*_}; echo ${tmp/\.*})
$ echo "source_file_issue_date: $source_file_issue_date"
source_file_issue_date: 20090323
$

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to extract a portion of a string from the whole string

How to extract a portion of a string from a full string using unix. For example: Say source string is = "req92374923.log" I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Discussion started by: ds_sastry
2 Replies

2. Shell Programming and Scripting

need help on sed (replace string without changing filename)

I have awhole bunch of files and I want to edit stringA with stringB without changing the filename. I have tried the following sed commands: sed "s/stringA/stringB/g" * This will print the correct results but does not actually save it with the new content of the file. when I do a cat on... (5 Replies)
Discussion started by: jjoves
5 Replies

3. Shell Programming and Scripting

Match portion of the filename

hi, I have a script which accept filename and process them, however, one of the file needs 'special' handling so I need to identify it, say the filename contains the word "STOCK" (i.e. NEWYORKSTOCKLIST20060627.txt), I want to check if the filename contains the word "STOCK", how can I do that?... (1 Reply)
Discussion started by: mpang_
1 Replies

4. Shell Programming and Scripting

extract string portion using sed

Hi All I have 3 files as listed below and highlighted in bold the portions of the filenames I need to extract: TOS_TABIN218_20090323.200903231830 TOS_TABIN219_1_20090323.200903231830 TOS_TABIN219_2_20090323.200903231830 I tried source_tabin_name=`echo $fname | sed 's/_.*//'` but I... (6 Replies)
Discussion started by: santam
6 Replies

5. Shell Programming and Scripting

How to extract portion of a string?

Hi Gurus, Would like to seek some help on how to extract a portion of string from log's output as shown below. Sample of raw data: piece handle=/test123/disk_dump/test123/df0_cntrl_PCPFCI20120404_68498 tag=TAG20120404T180035 comment=NONE piece... (13 Replies)
Discussion started by: superHonda123
13 Replies

6. Shell Programming and Scripting

extract every filename containing certain string in a directory and do some commend per file

Hi, Here is my question: suppose I have files like 1990_8xdaily_atmos.nc 1991_8xdaily_atmos.nc 1992_8xdaily_atmos.nc 1993_8xdaily_atmos.nc 1990_daily_atmos.nc 1991_daily_atmos.nc 1992_daily_atmos.nc 1993_daily_atmos.nc 1990_month_atmos.nc 1991_month_atmos.nc 1992_month_atmos.nc... (1 Reply)
Discussion started by: 1988PF
1 Replies

7. Shell Programming and Scripting

Extract string from filename

Hi I need to extract the string from file name filename: FILENAME_STRUT_01032013_XXXXXXX.TXT I want 01032013 from the above file name. number of characters may differ before the required string but underscores(-) are same number i.e. after second underscore. Please advise on this. ... (2 Replies)
Discussion started by: cnrj
2 Replies

8. 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

9. Shell Programming and Scripting

Extract filename from a given string

I want to extract the filename from a string. This is how I have the rawdata ina file /home/sid/ftp/testing/abc.txt /home/sid/ftp/tested/testing/def.txt /home/sid/sftp/date/misc/hij.txt i want a script which would provide me an output like this Directory ... (10 Replies)
Discussion started by: sidnow
10 Replies

10. UNIX for Beginners Questions & Answers

Extract a portion of string from each line in Linux

Hi I have to extract the destination path information from each record the file is of variable length so I will not be able to use the print command.The search should start on variable "destinationPath" and it should end at immediate "," also the first field has to be printed Input File:... (7 Replies)
Discussion started by: rkakitapalli
7 Replies
PHAR.EXTRACTTO(3)							 1							 PHAR.EXTRACTTO(3)

Phar::extractTo - Extract the contents of a phar archive to a directory

SYNOPSIS
public bool Phar::extractTo (string $pathto, [string|array $files], [bool $overwrite = false]) DESCRIPTION
Note This method requires the php.ini setting phar.readonly to be set to 0 in order to work for Phar objects. Otherwise, a PharException will be thrown. Extract all files within a phar archive to disk. Extracted files and directories preserve permissions as stored in the archive. The optional parameters allow optional control over which files are extracted, and whether existing files on disk can be overwritten. The sec- ond parameter files can be either the name of a file or directory to extract, or an array of names of files and directories to extract. By default, this method will not overwrite existing files, the third parameter can be set to true to enable overwriting of files. This method is similar to ZipArchive.extractTo(3). PARAMETERS
o $pathto - Path within an archive to the file to delete. o $files - The name of a file or directory to extract, or an array of files/directories to extract o $overwrite - Set to TRUE to enable overwriting existing files RETURN VALUES
returns TRUE on success, but it is better to check for thrown exception, and assume success if none is thrown. ERRORS
/EXCEPTIONS Throws PharException if errors occur while flushing changes to disk. EXAMPLES
Example #1 A Phar.extractTo(3) example <?php try { $phar = new Phar('myphar.phar'); $phar->extractTo('/full/path'); // extract all files $phar->extractTo('/another/path', 'file.txt'); // extract only file.txt $phar->extractTo('/this/path', array('file1.txt', 'file2.txt')); // extract 2 files only $phar->extractTo('/third/path', null, true); // extract all files, and overwrite } catch (Exception $e) { // handle errors } ?> SEE ALSO
PharData.extractTo(3). PHP Documentation Group PHAR.EXTRACTTO(3)
All times are GMT -4. The time now is 09:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy