Replace a word based upon the file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace a word based upon the file content
# 1  
Old 10-23-2018
Unfortunately, none of your attempts targets close to what you specify. Did you analyse the very precise error msgs, showing the exact location of the syntax fault? Are you sure about your fields' distribution (you specify two fields but reference $3)?

There are umpteen ways to skin a cat. How far would this get you?
Code:
awk -v SQ="'" '
$2 == "timestamp"       {$0 = "dataformat(" SQ "YYYY-MM-DD HH:NN:SS.sss)" SQ}
$2 == "date"            {$0 = "dataformat(" SQ "YYYY-MM-DD)" SQ}
1
' file
a smallint
dataformat('YYYY-MM-DD HH:NN:SS.sss)'
dataformat('YYYY-MM-DD)'
d varchar


EDIT: So close to this (which I saw only now...).

Last edited by RudiC; 10-23-2018 at 07:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

3. Shell Programming and Scripting

Sed: replace content from file with the content from file

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

4. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

5. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (1 Reply)
Discussion started by: perl_beginner
1 Replies

6. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

8. Shell Programming and Scripting

Change file content based on data

I have a Transaction File coming into the system. In this file, in all records the relevant data is as follows- Position 1:10 -> Transaction Code Position 252:255 -> 4 digit business code Now based on these 2 fields I have to alter value in Transaction code (Position 1:10)... (6 Replies)
Discussion started by: varunrbs
6 Replies

9. Shell Programming and Scripting

Dynamic naming based on file content

I was just thinking if there is a way where i can dynamically rename files based on the actual file content. I have a load of pdf's which have been named wrongly. (We normally put date first, then brief description, then title) So can a script be written wherin, it pulls out the date and title... (2 Replies)
Discussion started by: deaddevil
2 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question
NOTMUCH-SEARCH-TERMS(7) 				 Miscellaneous Information Manual				   NOTMUCH-SEARCH-TERMS(7)

NAME
notmuch-search-terms - Syntax for notmuch queries SYNOPSIS
notmuch count [options...] <search-term>... notmuch dump [ <filename> ] [--] [ <search-term>...] notmuch search [options...] <search-term>... notmuch show [options...] <search-term>... notmuch tag +<tag>|-<tag> [...] [--] <search-term>... DESCRIPTION
Several notmuch commands accept a common syntax for search terms. The search terms can consist of free-form text (and quoted phrases) which will match all messages that contain all of the given terms/phrases in the body, the subject, or any of the sender or recipient headers. As a special case, a search string consisting of exactly a single asterisk ("*") will match all messages. In addition to free text, the following prefixes can be used to force terms to match against specific portions of an email, (where <brack- ets> indicate user-supplied values): from:<name-or-address> to:<name-or-address> subject:<word-or-quoted-phrase> attachment:<word> tag:<tag> (or is:<tag>) id:<message-id> thread:<thread-id> folder:<directory-path> The from: prefix is used to match the name or address of the sender of an email message. The to: prefix is used to match the names or addresses of any recipient of an email message, (whether To, Cc, or Bcc). Any term prefixed with subject: will match only text from the subject of an email. Searching for a phrase in the subject is supported by including quotation marks around the phrase, immediately following subject:. The attachment: prefix can be used to search for specific filenames (or extensions) of attachments to email messages. For tag: and is: valid tag values include inbox and unread by default for new messages added by notmuch new as well as any other tag values added manually with notmuch tag. For id:, message ID values are the literal contents of the Message-ID: header of email messages, but without the '<', '>' delimiters. The thread: prefix can be used with the thread ID values that are generated internally by notmuch (and do not appear in email messages). These thread ID values can be seen in the first column of output from notmuch search The folder: prefix can be used to search for email message files that are contained within particular directories within the mail store. Only the directory components below the top-level mail database path are available to be searched. In addition to individual terms, multiple terms can be combined with Boolean operators ( and, or, not , etc.). Each term in the query will be implicitly connected by a logical AND if no explicit operator is provided, (except that terms with a common prefix will be implicitly combined with OR until we get Xapian defect #402 fixed). Parentheses can also be used to control the combination of the Boolean operators, but will have to be protected from interpretation by the shell, (such as by putting quotation marks around any parenthesized expression). Finally, results can be restricted to only messages within a particular time range, (based on the Date: header) with a syntax of: <initial-timestamp>..<final-timestamp> Each timestamp is a number representing the number of seconds since 1970-01-01 00:00:00 UTC. This is not the most convenient means of expressing date ranges, but until notmuch is fixed to accept a more convenient form, one can use the date program to construct timestamps. For example, with the bash shell the following syntax would specify a date range to return messages from 2009-10-01 until the current time: $(date +%s -d 2009-10-01)..$(date +%s) SEE ALSO
notmuch(1), notmuch-config(1), notmuch-count(1), notmuch-dump(1), notmuch-hooks(5), notmuch-new(1), notmuch-reply(1), notmuch-restore(1), notmuch-search(1), notmuch-show(1), notmuch-tag(1) Notmuch 0.13.2 2012-06-01 NOTMUCH-SEARCH-TERMS(7)