Sponsored Content
Top Forums Shell Programming and Scripting creating files and getting input from another file Post 302232321 by ajayyadavmca on Thursday 4th of September 2008 09:30:39 AM
Old 09-04-2008
creating files and getting input from another file

I have a file where i have files name with absolute path.
Ex: files.dat and contents are:
/root/xy/yz/zz/abc.txt
/root/xx/yy/zz/ac.txt
/root/xz/yz/zx/bc.txt
/root/xy/yz/zx/abcd.txt

now i want to create all above files(dummy files and can be 0 byte). i thought of using touch but it doesn't create directory.

i thought of taking path and create dir mkdir -p <path> and then touch but how to get that path? i know its easy just extract string till last "/" character but how?
thanks, Ajay
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

2. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

3. Shell Programming and Scripting

Creating a control file for a group of files

Hi, We have almost 45,000 data files created by a script daily. The file names are of format-ODS.POS.<pharmacyid>.<table name>.<timestamp>.dat. There will be one data file like this for each pharmacy and each table.(Totally around 45,000) The requirement is to create a control file for each... (2 Replies)
Discussion started by: Maya_Pillai
2 Replies

4. Shell Programming and Scripting

Creating Dynamic Input or daa files

Hi, I got a requirement to automate the process. We have SLA files, there are some 80 SLA files comes from 1.30pm - 5.30pm. I was asked to write a script to check for the SLA files in the load directory, if the files come then we got to send the mail to the group, if the mails doesnt come... (1 Reply)
Discussion started by: afahmed
1 Replies

5. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

6. Shell Programming and Scripting

Comparing two files and creating a new file

Hi, I want to compare two files based on the data in their first column. Both the files are not equal in their number of columns and number of entries or rows. The entries (only the first column) of the file1 should be compared with the entries (only the first column) of the file2. If the... (3 Replies)
Discussion started by: begin_shell
3 Replies

7. Shell Programming and Scripting

Creating two files out of one file

Hi members, I have a file with lots of text like this: asdsfkm dfsfomnow i want to extract only the rows with HUMAN as its 1st column for this I used : ruby -ne 'print if /^Human/; exit if /^TER/' $line | awk 'print $1, "\t"$2, "\t"$3, "\t"$4, "\t"$5}' >$line"new" This is creating a file... (1 Reply)
Discussion started by: CAch
1 Replies

8. Shell Programming and Scripting

Creating a file from input stream

Hi, Need some help with creating a file from input steam. Meaning from following command myfunc should be able to store the input stream to a file. echo a b c | myfunc The file thus created should have - a b c Here's what I've tried in myfunc() but didn't help - myfunc() { cat... (3 Replies)
Discussion started by: nexional
3 Replies

9. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

10. Programming

creating separate output file for each input file in python

Experts, Need your help for this. Please support My motive is to create seperate output file for each Input Files(File 1 and File2) in another folder say(/tmp/finaloutput) Input files File 1(1.1.1.1.csv) a,b,c 43,17104773,3 45,17104234,4 File 2(2.2.2.2.csv) a,b,c 43,17104773,1... (2 Replies)
Discussion started by: as7951
2 Replies
Path::Class::File(3)					User Contributed Perl Documentation				      Path::Class::File(3)

NAME
Path::Class::File - Objects representing files VERSION
version 0.26 SYNOPSIS
use Path::Class qw(file); # Export a short constructor my $file = file('foo', 'bar.txt'); # Path::Class::File object my $file = Path::Class::File->new('foo', 'bar.txt'); # Same thing # Stringifies to 'foo/bar.txt' on Unix, 'fooar.txt' on Windows, etc. print "file: $file "; if ($file->is_absolute) { ... } if ($file->is_relative) { ... } my $v = $file->volume; # Could be 'C:' on Windows, empty string # on Unix, 'Macintosh HD:' on Mac OS $file->cleanup; # Perform logical cleanup of pathname $file->resolve; # Perform physical cleanup of pathname my $dir = $file->dir; # A Path::Class::Dir object my $abs = $file->absolute; # Transform to absolute path my $rel = $file->relative; # Transform to relative path DESCRIPTION
The "Path::Class::File" class contains functionality for manipulating file names in a cross-platform way. METHODS
$file = Path::Class::File->new( <dir1>, <dir2>, ..., <file> ) $file = file( <dir1>, <dir2>, ..., <file> ) Creates a new "Path::Class::File" object and returns it. The arguments specify the path to the file. Any volume may also be specified as the first argument, or as part of the first argument. You can use platform-neutral syntax: my $dir = file( 'foo', 'bar', 'baz.txt' ); or platform-native syntax: my $dir = dir( 'foo/bar/baz.txt' ); or a mixture of the two: my $dir = dir( 'foo/bar', 'baz.txt' ); All three of the above examples create relative paths. To create an absolute path, either use the platform native syntax for doing so: my $dir = dir( '/var/tmp/foo.txt' ); or use an empty string as the first argument: my $dir = dir( '', 'var', 'tmp', 'foo.txt' ); If the second form seems awkward, that's somewhat intentional - paths like "/var/tmp" or "Windows" aren't cross-platform concepts in the first place, so they probably shouldn't appear in your code if you're trying to be cross-platform. The first form is perfectly fine, because paths like this may come from config files, user input, or whatever. $file->stringify This method is called internally when a "Path::Class::File" object is used in a string context, so the following are equivalent: $string = $file->stringify; $string = "$file"; $file->volume Returns the volume (e.g. "C:" on Windows, "Macintosh HD:" on Mac OS, etc.) of the object, if any. Otherwise, returns the empty string. $file->basename Returns the name of the file as a string, without the directory portion (if any). $file->is_dir Returns a boolean value indicating whether this object represents a directory. Not surprisingly, "Path::Class::File" objects always return false, and "Path::Class::Dir" objects always return true. $file->is_absolute Returns true or false depending on whether the file refers to an absolute path specifier (like "/usr/local/foo.txt" or "WindowsFoo.txt"). $file->is_relative Returns true or false depending on whether the file refers to a relative path specifier (like "lib/foo.txt" or ".Foo.txt"). $file->cleanup Performs a logical cleanup of the file path. For instance: my $file = file('/foo//baz/./foo.txt')->cleanup; # $file now represents '/foo/baz/foo.txt'; $dir->resolve Performs a physical cleanup of the file path. For instance: my $dir = dir('/foo/baz/../foo.txt')->resolve; # $dir now represents '/foo/foo.txt', assuming no symlinks This actually consults the filesystem to verify the validity of the path. $dir = $file->dir Returns a "Path::Class::Dir" object representing the directory containing this file. $dir = $file->parent A synonym for the "dir()" method. $abs = $file->absolute Returns a "Path::Class::File" object representing $file as an absolute path. An optional argument, given as either a string or a "Path::Class::Dir" object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used. $rel = $file->relative Returns a "Path::Class::File" object representing $file as a relative path. An optional argument, given as either a string or a "Path::Class::Dir" object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used. $foreign = $file->as_foreign($type) Returns a "Path::Class::File" object representing $file as it would be specified on a system of type $type. Known types include "Unix", "Win32", "Mac", "VMS", and "OS2", i.e. anything for which there is a subclass of "File::Spec". Any generated objects (subdirectories, files, parents, etc.) will also retain this type. $foreign = Path::Class::File->new_foreign($type, @args) Returns a "Path::Class::File" object representing a file as it would be specified on a system of type $type. Known types include "Unix", "Win32", "Mac", "VMS", and "OS2", i.e. anything for which there is a subclass of "File::Spec". The arguments in @args are the same as they would be specified in "new()". $fh = $file->open($mode, $permissions) Passes the given arguments, including $file, to "IO::File->new" (which in turn calls "IO::File->open" and returns the result as an "IO::File" object. If the opening fails, "undef" is returned and $! is set. $fh = $file->openr() A shortcut for $fh = $file->open('r') or croak "Can't read $file: $!"; $fh = $file->openw() A shortcut for $fh = $file->open('w') or croak "Can't write $file: $!"; $file->touch Sets the modification and access time of the given file to right now, if the file exists. If it doesn't exist, "touch()" will make it exist, and - YES! - set its modification and access time to now. $file->slurp() In a scalar context, returns the contents of $file in a string. In a list context, returns the lines of $file (according to how $/ is set) as a list. If the file can't be read, this method will throw an exception. If you want "chomp()" run on each line of the file, pass a true value for the "chomp" or "chomped" parameters: my @lines = $file->slurp(chomp => 1); You may also use the "iomode" parameter to pass in an IO mode to use when opening the file, usually IO layers (though anything accepted by the MODE argument of "open()" is accepted here). Just make sure it's a reading mode. my @lines = $file->slurp(iomode => ':crlf'); my $lines = $file->slurp(iomode => '<:encoding(UTFaXX8)'); The default "iomode" is "r". $file->spew( $content ); The opposite of "slurp", this takes a list of strings and prints them to the file in write mode. If the file can't be written too, this method will throw an exception. The content to be written can be either an array ref or a plain scalar. If the content is an array ref then each entry in the array will be written to the file. You may use the "iomode" parameter to pass in an IO mode to use when opening the file, just like "slurp" supports. $file->spew(iomode => '>:raw', $content); The default "iomode" is "w". $file->traverse(sub { ... }, @args) Calls the given callback on $file. This doesn't do much on its own, but see the associated documentation in Path::Class::Dir. $file->remove() This method will remove the file in a way that works well on all platforms, and returns a boolean value indicating whether or not the file was successfully removed. "remove()" is better than simply calling Perl's "unlink()" function, because on some platforms (notably VMS) you actually may need to call "unlink()" several times before all versions of the file are gone - the "remove()" method handles this process for you. $st = $file->stat() Invokes "File::stat::stat()" on this file and returns a "File::stat" object representing the result. $st = $file->lstat() Same as "stat()", but if $file is a symbolic link, "lstat()" stats the link instead of the file the link points to. $class = $file->dir_class() Returns the class which should be used to create directory objects. Generally overridden whenever this class is subclassed. AUTHOR
Ken Williams, kwilliams@cpan.org SEE ALSO
Path::Class, Path::Class::Dir, File::Spec perl v5.16.2 2013-08-25 Path::Class::File(3)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy