Sponsored Content
Top Forums Shell Programming and Scripting How to handle variable with special character? Post 303026285 by Corona688 on Friday 23rd of November 2018 10:42:34 AM
Old 11-23-2018
I think I finally get it -- that grep is supposed to find the line in the file you want. What for, I'm not certain, as you don't use the file for anything, yet. So I'm also wild-guessing that the 'dir' part of the file ends up being part of the destination file name.

Please try this code and see if it does anything like what you want. It won't actually move any files, just print 'mv inputfile outputfile'.
Code:
#!/bin/ksh

# We use a function, so overwriting $1 $2 ... won't affect anything outside
function checkfile {
        dir="$1"
        set -- "${2}"* # Match one or more files, placing in local $1 $2 ...
        if [ ! -f "${1}" ]
        then
                echo "${1} not found" >&2
                return 1
        fi

        echo mv "${1}" "${1}_${dir}"
}

while IFS=", " read dir filename # Split input upon spaces and commas
do
        # Skip lines where filename doesn't match the argument given.
        [ "$1" = "$filename" ] || continue
        # call checkfile.  Inside checkfile, $1=$dir and $2=$filename
        checkfile "$dir" "$filename"
done<masterfile


Last edited by Corona688; 11-23-2018 at 11:49 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

special character ?

hey there im a bit stuck on executing commands that include the special character '?'. can someone recommend a way on how i would be able to execute it?? i thought the glob function could be useful (still mite be) but upon entering the command 'ls pars?' it listed all the files in the... (1 Reply)
Discussion started by: mile1982
1 Replies

2. Shell Programming and Scripting

How ro handle backslash character in grep?

Hi , I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it. Diffu.txt ======== 1159c1159 < <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466"> --- > <td... (1 Reply)
Discussion started by: rajbal
1 Replies

3. Shell Programming and Scripting

special character

Hi, I am trying to unload file from a database. Which contains few lines with the character below. Rest of the data was unloaded appropriately. a) What does this below character means? b) How can i remove it, I already have sed '/^$/d' c) Will this effect the file by any means... (4 Replies)
Discussion started by: tostay2003
4 Replies

4. Shell Programming and Scripting

Special character \

Hi, In the shell script, i need to remove the special charater "\" with "\\". For example, i need to replace "D:\FXT\ABC.TXT" with "D:\\FXT\\ABC.TXT". However, when trying to do something like , i get the below error :- -->echo "D:\FXT\ABC.TXT" | sed -e 's#\#\\#g' sed: 0602-404 Function... (7 Replies)
Discussion started by: amit_arora
7 Replies

5. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

6. Shell Programming and Scripting

How to handle variable with spaces in ksh

I'm having issue capturing a value from file.list with a multiple spaces in a variable $i, tried various options like using double quotes, no quotes, single quotes, curly braces but to no avail. cat file.list aaa test bbb ccc test ddd eee test fff for i in `cat file.list` do echo "$i";... (2 Replies)
Discussion started by: mbak
2 Replies

7. Shell Programming and Scripting

How to substitute variable in sed for special character?

Hi , I have input file like below Hi this is "vinoth". Hi happy to work with 'unix' USA(united states of America) My script variables are below : Dquote=Ộ Squote=&#$567 Obrac=&^986 Cbrac=&^745 I want to read the variables in my SED command to replace the double quote,single... (9 Replies)
Discussion started by: vinothsekark
9 Replies

8. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

9. Shell Programming and Scripting

Handle special characters in awk -F

Hello Folks, Need to bisect strings based on a subset. Below works good. echo /a/b/c/d | awk -F"/c/d$" '{print $1}' /a/b However, it goes awry with special characters. echo /a/b/c+/d | awk -F"/c+/d$" '{print $1}' /a/b/c+/d Desired output: /a/b Escaping the special characters... (11 Replies)
Discussion started by: vibhor_agarwali
11 Replies

10. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies
fscat_vxfs(1M)															    fscat_vxfs(1M)

NAME
fscat_vxfs: fscat - cat a VxFS file system SYNOPSIS
output-file] offset] length] block_size] special DESCRIPTION
provides an interface to a VxFS snapshot file system, similar to that provided by invoked on the block or character special file of regular VxFS file systems. works when executed on the special device of any VxFS file system. On most VxFS file systems, the block or character special file for the file system provides access to a raw image of the file system to back up the file system to tape. On a snapshot file system, access to the corresponding block or character special file provides little useful information. provides a stream of bytes representing the file system snapshot. This datastream is written by default to standard output, although the output-file option can be used to specify another destination. The datastream on standard output can be processed several ways, such as in a pipeline, or written to a tape. By default, the output is a stream of bytes that starts at the beginning of the file system and continues to the last byte. On a snapshot file system, data is read from the file system using special ioctls on the mount point. On other VxFS file systems, data is read from the specified special file. Unless otherwise specified, data is written to standard output. All numbers entered as option arguments can have as a prefix to indicate octal, or as a prefix to indicate hexadecimal. A or can be appended to indicate the value is in 512-byte blocks, a or to indicate the value is in kilobytes, an or to indicate the value is in megabytes, or a or to indicate the value is in gigabytes. An appended letter can be separated from the number by a space, in which case the letter and number should be enclosed in a set of quotes. For example: All numbers entered as options must be in multiples of 512 bytes. For example, a value of 5713 as an offset is rejected. Options recognizes the following options: Specify the output block size, in bytes. block_size must be less than or equal to 1 megabyte. Specify the VxFS file system type. Specify an output file in which to write the datastream. Specify the transfer length, in bytes. A length of includes the remainder of the file system after the specified offset. Specify the starting offset in bytes. Operands recognizes the following operand: special Name of the special device from which the VxFS file system is accessed. Notes Snapshot file systems are only available with the HP OnLineJFS product. A snapshot file system cannot be written to. A snapshot file system exists only as long as it is mounted; once unmounted, the special file no longer contains a snapshot file system. When is run on a mounted VxFS snapshot, the content of free blocks (that is, blocks not allocated to any file or metadata) is undefined. The content of free blocks can change after additional data is written to the primary file system, but blocks associated with files always display the content they had when the snapshot was created. does not work with Storage Checkpoints. SEE ALSO
dd(1), fs_vxfs(4), vxfsio(7). fscat_vxfs(1M)
All times are GMT -4. The time now is 07:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy