01-20-2011
file content as a part of an if-statement
Hello,
I have following problem.
I have the result of a database request. I preparated the result via sed, etc. as a string in a file.
The string in the file is:
($3==1 || $3==2 || $3==3 || $3==4)
Now I want to use the String as a command in an if-statement.
So I assigned the string to a variable:
ABC=$(<dir/file)
So far - so good:
echo $ABC gives me as a result: ($3==1 || $3==2 || $3==3 || $3==4)
But with nawk it doesn't work.
For clarification: If I would use the string directly (and so static), my awk would be written like here:
#If we find the values 1,2,3 or 4 in column 3, so change the value in column 4 into 10 in the relevant rows.
nawk '{FS=";";OFS=";"; if ($3==1 || $3==2 || $3==3|| $3==4) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt
But dynamically it doesn't work. My idea was following:
nawk '{FS=";";OFS=";"; if ($ABC) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt
I tested everything, with echo $ABC, cat, different brackets... but without success.
Is anybody able to help me and explain to me what I have to change, please?
Thanks a lot and Kind Regards
Dr_Aleman
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Experts.
I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies
2. Shell Programming and Scripting
I may not being doing this description justice, but I'll give it a try.
I created a mailx script; there will be several messages using the same script where the only difference is the content. So I figured I'd make the content of the message a variable retrieved from a separate file. I have five... (5 Replies)
Discussion started by: royarellano
5 Replies
3. Shell Programming and Scripting
Hi,
I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this:
Name =A
xxxxxx
yyyyyy
zzzzzz
aaaaaa
bbbbbb
Value = 57
This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies
4. Programming
All,
I have a log file containing lots of data now i want to extract all text between block below(names) without the title or end pattern but only names,
++++START++++
SCOTT TIGER
HENRY PAUL
JARED OTIENO
OMOLLO JA NIGERIA
++++END++++
the names i want to return and store in a variable in... (1 Reply)
Discussion started by: Scott2000
1 Replies
5. Shell Programming and Scripting
Hi,
I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C.
Thanks a lot!!
Here is a sample of my question.
e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies
6. Shell Programming and Scripting
Hi,
I have a files in a directory as below :-
ls -1
mqdepth-S1STC02
proc-mq-S1STC01
proc-mq-S1STC02
proc-mq-S1STC03
Whereever i have S1STC i need to copy them into new file with file name S2STC.
expected output :-
ls -1
mqdepth-S2STC02
proc-mq-S2STC01
proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies
7. Shell Programming and Scripting
hi all,
i had the below script
x=`cat input.txt |wc -1`
awk 'NR>1 && NR<'$x' ' input.txt > output.txt
by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies
8. Shell Programming and Scripting
I have a variable and assigned the following values
***XYZ_201519_20150929140642_20150929140644_211_0_0_211
I need to read this variable from backward and stop read when I get first underscore (_)
In this scenario I should get 211
Thanks
Kris (3 Replies)
Discussion started by: mkris
3 Replies
9. Shell Programming and Scripting
Hi friends, here is my problem.
I have three files like this..
cat file1.txt
=======
unix is best
unix is best
linux is best
unix is best
linux is best
linux is best
unix is best
unix is best
cat file2.txt
========
Windows performs better
Mac OS performs better
Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies
LEARN ABOUT PHP
pg_prepare
PG_PREPARE(3) PG_PREPARE(3)
pg_prepare - Submits a request to create a prepared statement with the given parameters, and waits for completion.
SYNOPSIS
resource pg_prepare ([resource $connection], string $stmtname, string $query)
DESCRIPTION
pg_prepare(3) creates a prepared statement for later execution with pg_execute(3) or pg_send_execute(3). This feature allows commands that
will be used repeatedly to be parsed and planned just once, rather than each time they are executed. pg_prepare(3) is supported only
against PostgreSQL 7.4 or higher connections; it will fail when using earlier versions.
The function creates a prepared statement named $stmtname from the $query string, which must contain a single SQL command. $stmtname may
be "" to create an unnamed statement, in which case any pre-existing unnamed statement is automatically replaced; otherwise it is an error
if the statement name is already defined in the current session. If any parameters are used, they are referred to in the $query as $1, $2,
etc.
Prepared statements for use with pg_prepare(3) can also be created by executing SQL PREPARE statements. (But pg_prepare(3) is more flexi-
ble since it does not require parameter types to be pre-specified.) Also, although there is no PHP function for deleting a prepared state-
ment, the SQL DEALLOCATE statement can be used for that purpose.
PARAMETERS
o $connection
- PostgreSQL database connection resource. When $connection is not present, the default connection is used. The default connection
is the last connection made by pg_connect(3) or pg_pconnect(3).
o $stmtname
- The name to give the prepared statement. Must be unique per-connection. If "" is specified, then an unnamed statement is cre-
ated, overwriting any previously defined unnamed statement.
o $query
- The parameterized SQL statement. Must contain only a single statement. (multiple statements separated by semi-colons are not
allowed.) If any parameters are used, they are referred to as $1, $2, etc.
RETURN VALUES
A query result resource on success or FALSE on failure.
EXAMPLES
Example #1
Using pg_prepare(3)
<?php
// Connect to a database named "mary"
$dbconn = pg_connect("dbname=mary");
// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
// Execute the same prepared query, this time with a different parameter
$result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
?>
SEE ALSO
pg_execute(3), pg_send_execute(3).
PHP Documentation Group PG_PREPARE(3)