Sponsored Content
Top Forums Shell Programming and Scripting Want to read data from a file name.txt and search it in another file and then matching... Post 302594511 by gary_w on Tuesday 31st of January 2012 12:57:49 PM
Old 01-31-2012
ksh93 on Solaris:

Code:
#!/usr/dt/bin/dtksh

#  Declare constants
typeset -r RESULTSFILE=results
typeset -r INFILE=name.txt
typeset -r SOURCEFILE=source

#  Clear or create output file.
> $RESULTSFILE

while read line_in
do
  print "Search results for [${line_in}]:" >> $RESULTSFILE
  grep "$line_in" $SOURCEFILE >> $RESULTSFILE
done < $INFILE

exit 0

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to read last line of a txt file?

I need to read the last file for a particular day, such as, "Jun 13" because the CSV file is cumulative for the entire day, so I don't want all the previous files, I just want the last file, for that day. I ran an 'ls -al | grep "June 13" > myLs.txt' (simplified) to list all files from that day.... (2 Replies)
Discussion started by: yongho
2 Replies

2. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

3. UNIX for Dummies Questions & Answers

can't read a .txt file

Hello, I have a set of .txt files I cannot read. This is a part of what I see. Is there a way to view these files? _MO<P.6D@K;WU<B$X-;)SIV/ROO!UL+1P=VTT-?,SLC`MI/6QMS#UYGGT\+)C=#\UIO`TL/0]=#/T) it's about 3 pages. Thanks for your help. Joe (3 Replies)
Discussion started by: rcracerjoe
3 Replies

4. Shell Programming and Scripting

Script to read file and extract data by matching pattern

Hello, I have a file ( say file1) which has lines like below. xxxx:xxxx,yyyy,1234,efgh zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo dddd:dddd here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by "," In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies

5. Shell Programming and Scripting

shellscript to read data from txt file and import to oracle db

Hi all, Help needed urgently. I am currently writing a shellscript to read data/record from a flat file (.txt) file, and import/upload the data to oracle database. The script is working fine, but it takes too long time (for 18000 records, it takes around 90 mins). I guess it takes so long... (1 Reply)
Discussion started by: robot_mas
1 Replies

6. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

7. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

8. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

9. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

10. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies
typeset(1)							   User Commands							typeset(1)

NAME
typeset, whence - shell built-in functions to set/get attributes and values for shell variables and functions SYNOPSIS
typeset [+- HLRZfilrtux [n]] [name[=value]]... whence [-pv] name... ksh93 ++typeset [+-AHflbnprtux] [+-EFLRZi[n]] [vname[=value]] whence [-afpv] name... DESCRIPTION
ksh typeset sets attributes and values for shell variables and functions. When typeset is invoked inside a function, a new instance of the variables name is created. The variables value and type are restored when the function completes. The following list of attributes can be specified: -f The names refer to function names rather than variable names. No assignments can be made and the only other valid flags are -t, -u and -x. The flag -t turns on execution tracing for this function. The flag -u causes this function to be marked undefined. The FPATH variable is searched to find the function definition when the function is referenced. The flag -x allows the function definition to remain in effect across shell procedures invoked by name. -H This flag provides UNIX to hostname file mapping on non-UNIX machines. -i Parameter is an integer. This makes arithmetic faster. If n is non-zero it defines the output arithmetic base; otherwise, the first assignment determines the output base. -l All uppercase characters are converted to lowercase. The uppercase flag, -u is turned off. -L Left justify and remove leading blanks from value. If n is non-zero it defines the width of the field; otherwise, it is determined by the width of the value of first assignment. When the variable is assigned to, it is filled on the right with blanks or truncated, if necessary, to fit into the field. Leading zeros are removed if the -Z flag is also set. The -R flag is turned off. -r The specified names are marked readonly and these names cannot be changed by subsequent assignment. -R Right justify and fill with leading blanks. If n is non-zero it defines the width of the field, otherwise it is determined by the width of the value of first assignment. The field is left filled with blanks or truncated from the end if the variable is reassigned. The -L flag is turned off. -t Tags the variables. Tags are user definable and have no special meaning to the shell. -u All lowercase characters are converted to uppercase characters. The lowercase flag, -l is turned off. -x The specified names are marked for automatic export to the environment of subsequently-executed commands. -Z Right justify and fill with leading zeros if the first non-blank character is a digit and the -L flag has not been set. If n is non- zero it defines the width of the field. Otherwise, it is determined by the width of the value of first assignment. The -i attribute can not be specified along with -R, -L, -Z, or -f. Using + rather than - causes these flags to be turned off. If no name arguments are specified but flags are specified, a list of names (and optionally the values) of the variables which have these flags set is printed. (Using + rather than - keeps the values from being printed.) If no names and flags are specified, the names and attributes of all variables are printed. For each name, whence indicates how it would be interpreted if used as a command name. The -v flag produces a more verbose report. The -p flag does a path search for name even if name is an alias, a function, or a reserved word. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ksh93 If the -f option is not specified, typeset sets, unsets, or displays attributes of variables as specified with the options. If the first option is specified with a - then the attributes are set for each of the specified names. If the first option is specified with a +, then the specified attributes are unset. If =value is specified, value is assigned before the attributes are set. When typeset is called inside a function that is defined with the function reserved word, and name does not contain a ., a local variable statically scoped to that function is created. Not all option combinations are possible. For example, the numeric options -i, -E, and -F cannot be specified with the justification options -L, -R, and -Z. The following preset aliases are set by the shell: float typeset -E functions typeset -f integer typeset -i nameref typeset -n If no names are specified, variables that have the specified options are displayed. If the first option is specified with a leading - then the name and value of each variable is written to standard output. Otherwise, only the names are written. If no options or only the -p option are specified, the names and attributes of all variables that have attributes are written to standard output. When -f is specified, the names displayed are function names. If -f is specified, then each name refers to a function and the only valid options are -u and -t. In this case no =value can be specified. typeset is built-in to the shell as a declaration command so that field splitting and pathname expansion are not performed on the argu- ments. Tilde expansion occurs on value. The following options are supported by the typeset built-in command in ksh93: -a Indexed array. This is the default. -A Associative array. Each name is converted to an associative array. If a variable already exists, the current value becomes index 0. -b Each name can contain binary data. Its value is the mime base64 encoding of the data. This option can be used with -Z, to specify fixed sized fields. -E [n] Floating point number represented in scientific notation. n specifies the number of significant figures when the value is expanded. The default value is 10. -f Each of the options and names refers to a function. -F [n] Floating point. n is the number of places after the decimal point when the value is expanded. The default value is 10. -H Hostname mapping. Each name holds a native pathname. Assigning a UNIX format pathname causes it to be converted to a pathname suitable for the current host. This has no effect when the native system is UNIX. -i [base] An integer. base represents the arithmetic base from 2 to 64. The option value can be omitted. The default value is 10. -l Convert uppercase characters to lowercase characters. Unsets the -u option. When used with -i, -E, or -F indicates long vari- ant. -L [n] Left justify. If n is specified, it represents the field width. If the -Z attribute is also specified, then leading zeros are stripped. The option value can be omitted. -n Name reference. The value is the name of a variable that name references. name cannot contain a .. -p Causes the output to be in a format that can be used as input to the shell to recreate the attributes for variables. -r Enables read-only. Once this option is enabled, it cannot be disabled. See readonly(1). -R [n] Right justify. If n is specified it represents the field width. If the -Z option is also specified, zeros are used as the fill character. Otherwise, SPACEs are used. -s Restricts integer size to short when used with -i. -t When used with -f, enables tracing for each of the specified functions. Otherwise, -t is a user defined attribute and has no meaning to the shell. -T tname tname is the name of a type name given to each name. -u Without -f or -i, converts lowercase characters to uppercase and unsets -l. When used with -f, specifies that name is a func- tion that has not yet been loaded. When used with -i specifies that the value is displayed as an unsigned integer. -x Puts each name on the export list. See export(1). name cannot contain a .. -Z [n] Zero fill. If n is specified it represents the field width. The option value can be omitted. The following exit values are returned by typeset in ksh93: 0 Successful completion. >0 An error occurred. If the -v is not specified, whence writes on standard output an absolute pathname, if any, corresponding to name based on the complete search order that the shell uses. If name is not found, no output is produced. If the -v is specified, the output from whence also contains information that indicates how the specified name would be interpreted by the shell in the current execution environment. The following options are supported by the whence built-in command in ksh93: -a Display all uses for each name rather than the first. -f Do not check for functions. -p Do not check to see if name is a reserved word, a built-in, an alias, or a function. -v For each name specified, the shell displays a line that indicates if that name is one of the following: o Reserved word o Alias o Built-in o Undefined function o Function o Tracked alias o Program o Not found The following exit values are returned by whence in ksh93: 0 Successful completion. Each name was found by the shell. 1 One or more names were not found by the shell. >1 An error occurred. On this manual page, ksh93(1) commands that are preceded by one or two + (plus signs) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. They are not valid function names. 5. Words, following a command preceded by ++ that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), ksh93(1), readonly(1)set(1), sh(1), attributes(5) SunOS 5.11 13 Mar 2008 typeset(1)
All times are GMT -4. The time now is 04:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy