Sponsored Content
Top Forums Shell Programming and Scripting To check the file and remove header before copying Post 302999327 by rohit_shinez on Saturday 17th of June 2017 01:06:42 AM
Old 06-17-2017
Hi Don,

I agree with your point so is there a best way to tune the code, Like remove header from only the file which ends with _01.txt and copy to respective folders before i copy to destination folder and also i am using multiple if conditions because i need to copy the files to respective destination folders based on property file.Below code which is making redundant

Code:
if [ "$i" == "aus" ]
then
if [ -f $file ]
then

      	cp $file /output/aus/
else 
	echo "No aus files"

fi

elif [ "$i" == "nz" ]
if [ -f $file ]
then

      	cp $file /output/nz/
else 
	echo "No nz files"

fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove header(first line) and trailer(last line) in ANY given file

Hi, I need some help in removing the header (first line) and the trailer (last line) in a give file... The data file actually comes in EBCDIC format and I converted it into ASCII.. Now I need to strip off the first line and the last line.. I think we can use sed to do something like this:... (2 Replies)
Discussion started by: madhunk
2 Replies

2. UNIX for Dummies Questions & Answers

Copy all the files with time stamp and remove header,trailer from file

All, I am new to unix and i have the following requirement. I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file.. Could... (35 Replies)
Discussion started by: ksrams
35 Replies

3. Shell Programming and Scripting

Check file size and remove files

Hi, Here we have a situation where we have to check the file size and if the file size is greater than 0 bytes then remove the files from the directory. 1)EdwTrxn 2)EdwPost 3)EdwTndr 4)EdwSls 5)EdwSlsRej 6)EdwTndrRej Files will be created in the directory in the following manner. ... (5 Replies)
Discussion started by: srivsn
5 Replies

4. UNIX for Dummies Questions & Answers

Check header of file, without opening the file

if we happen to have a very big .csv file we cannot or dont care to edit, is there a way to check if the file contains a header row? (2 Replies)
Discussion started by: lydiaflamp
2 Replies

5. Shell Programming and Scripting

Copying the Header & footer Information to the Outfile.

Hi I am writing a perl script which checks for the specific column values from a file and writes to the OUT file. So the feed file has a header information and footer information. I header information isaround107 lines i.e. Starts with START-OF-FILE ....... so on .... ... (11 Replies)
Discussion started by: filter
11 Replies

6. Shell Programming and Scripting

Remove last few characters in a file but keeping Header and trailer intact

Hi All, I am trying write a simple command using AWK and SED to this but without any success. Here is what I am using: head -1 test1.txt>test2.txt|sed '1d;$d' test1.txt|awk '{print substr($0,0,(length($0)-2))}' >>test2.txt|tail -1 test1.txt>>test2.txt Input: Header 1234567 abcdefgh... (2 Replies)
Discussion started by: nvuradi
2 Replies

7. Shell Programming and Scripting

Remove the file content based on the Header of the file

Hi All, I want to remove the content based on the header information . Please find the example below. File1.txt Name|Last|First|Location|DepId|Depname|DepLoc naga|rr|tion|hyd|1|wer|opr Nava|ra|tin|gen|2|wera|opra I have to search for the DepId and remove the data from the... (5 Replies)
Discussion started by: i150371485
5 Replies

8. UNIX for Advanced & Expert Users

How to check or remove IP address from a hashed known_hosts file?which

Hi, In my server, the hostname and IP addresses are added to the known_hosts which then be hashed by ssh-keygen -H -f. Is it possible to check if an IP address has already been added to the hashed known_hosts to avoid duplications (I think there will be problems if there are duplicated IP... (3 Replies)
Discussion started by: hce
3 Replies

9. UNIX for Dummies Questions & Answers

Check for empty line at end of a dynamic header in each file

Hi Folks, I have a requirement to develop a shell script. PFB my requirement, Requirement: I need to check an empty line after the end of each header in respective file and if a empty line is present simply echo file OK and if empty line is not present echo "Adding empty line" and add an... (6 Replies)
Discussion started by: tpk
6 Replies

10. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies
REFILE(1)							     [nmh-1.5]								 REFILE(1)

NAME
refile - file message in other folders SYNOPSIS
refile [msgs] [-draft] [-link | -nolink] [-preserve | -nopreserve] [-unlink | -nounlink] [-src +folder] [-file file] [-rmmproc program] [-normmproc] +folder1 ... [-version] [-help] DESCRIPTION
Refile moves (see mv(1)) or links (see ln(1)) messages from a source folder into one or more destination folders. If you think of a message as a sheet of paper, this operation is not unlike filing the sheet of paper (or copies) in file cabinet folders. When a message is filed, it is linked into the destination folder(s) if possible, and is copied otherwise. As long as the destination folders are all on the same file system, multiple filing causes little storage overhead. This facility provides a good way to cross-file or multiply-index messages. For example, if a message is received from Jones about the ARPA Map Project, the command refile cur +jones +Map would allow the message to be found in either of the two folders `jones' or `Map'. You may specify the source folder using -src +folder. If this is not given, the current folder is used by default. If no message is spec- ified, then `cur' is used by default. The option -file file directs refile to use the specified file as the source message to be filed, rather than a message from a folder. Note that the file should be a validly formatted message, just like any other nmh message. It should NOT be in mail drop format (to con- vert a file in mail drop format to a folder of nmh messages, see inc(1)). If a destination folder doesn't exist, refile will ask if you want to create it. A negative response will abort the file operation. If the standard input for refile is not a tty, then refile will not ask any questions and will proceed as if the user answered "yes" to all questions. The option -link preserves the source folder copy of the message (i.e., it does a ln(1) rather than a mv(1)), whereas, -nolink (the default) deletes the filed messages from the source folder. Normally when a message is refiled, for each destination folder it is assigned the number which is one above the current highest message number in that folder. Use of the -preserv switch will override this message renaming, and try to preserve the number of the message. If a conflict for a particular folder occurs when using the -preserve switch, then refile will use the next available message number which is above the message number you wish to preserve. If -link is not specified (or -nolink is specified), the filed messages will be removed from the source folder. The default is to remove these messages by renaming them with a site-dependent prefix (usually a comma). Such files will then need to be removed in some manner after a certain amount of time. Many sites arrange for cron to remove these files once a day, so check with your system administrator. Alternately, if you wish for refile to really remove the files representing these messages from the source folder, you can use the -unlink switch (not to be confused with the -link switch). But messages removed by this method cannot be later recovered. If you prefer a more sophisticated method of `removing' the messages from the source folder, you can define the rmmproc profile component. For example, you can add a profile component such as rmmproc: /home/coleman/bin/rmm_msgs then refile will instead call the named program or script to handle the message files. The user may specify -rmmproc program on the command line to override this profile specification. The -normmproc option forces the message files to be deleted by renaming or unlinking them as described above. The -draft switch tells refile to file the <mh-dir>/draft. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder Folder-Protect: To set mode when creating a new folder rmmproc: Program to delete the message SEE ALSO
folder(1), rmf(1), rmm(1) DEFAULTS
`-src +folder' defaults to the current folder `msgs' defaults to cur `-nolink' `-nounlink' `-nopreserve' CONTEXT
If -src +folder is given, it will become the current folder. If neither -link nor `all' is specified, the current message in the source folder will be set to the last message specified; otherwise, the current message won't be changed. If the "Previous-Sequence" profile entry is set, in addition to defining the named sequences from the source folder, refile will also define those sequences for the destination folders. See mh-sequence (5) for information concerning the previous sequence. BUGS
Since refile uses your rmmproc to delete the message, the rmmproc must NOT call refile without specifying -normmproc, or you will create an infinite loop. MH.6.8 11 June 2012 REFILE(1)
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy