Sponsored Content
Top Forums Shell Programming and Scripting awk search/replace specific field, using variables for regexp & subsitution then overwrite file Post 302704765 by cyphex on Sunday 23rd of September 2012 05:46:01 AM
Old 09-23-2012
I used the sed code instead of the awk command and this has given me exactly what I wanted!
Thanks for the help guys
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search and replace using awk with variables

Hi, I have been trying to use awk with variables that needs to search for a pattern and replace it with another pattern, the patterns are supplied in a variable. I have tried several different ways without success and hope that someone can help me. Here are the details echo $UPC 07007457809... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

awk search and replace and overwrite file

hi, i am doing awk '{gsub("hello", "bye", $0); print}' test.dat but I want to actually store the results of this global change into the file test.dat itself, i.e. I don't want the results to come to stdout, I want the results to overwrite the initial file how can I do this? thanks (3 Replies)
Discussion started by: JamesByars
3 Replies

3. Shell Programming and Scripting

awk search and replace field

I am writing a c++ program that has many calls of pow(input,2). I now realize that this is slowing down the program and these all should be input * input for greater speed. There should be a simple way of doing this replacement throughout my file with awk, but I am not very familiar with awk.... (2 Replies)
Discussion started by: bluejayek
2 Replies

4. Shell Programming and Scripting

awk how to replace specific field with new value

I need to replace specific field (x) in a table with new value (y): Input: 1 2 3 4 5 x 6 7 8 9 0 0 Output: 1 2 3 4 5 y 6 7 8 9 0 0 I have no idea how to do this. (10 Replies)
Discussion started by: setepo
10 Replies

5. Shell Programming and Scripting

AWK How to replace a field using 2 shell variables?

Hello everybody: I want to replace any field $2 of any file line (f.i. test.txt) matching $1 with a shell variable. $ cat test.txt F 0 B A H -12.33 Now I'm going to ask the value of variable B: $ SEARCHVAR=B $ OLDVAL=$(awk -v SEARCHVAR="$SEARCHVAR"... (4 Replies)
Discussion started by: basalt
4 Replies

6. Shell Programming and Scripting

Advanced AWK Regexp substring to int & Replace

Hi! I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased. Example the content of the textfile.txt hello version = x bye This include three steps 1. First find the char after... (2 Replies)
Discussion started by: Beachboy72
2 Replies

7. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

8. Shell Programming and Scripting

awk search and replace in a targeted field instead of $0

Hi I would like to apply this gawk command: gawk '{$0=gensub(/\y+\y/,"","g"); print}' file not to the whole $0 but just to the part of $0 that is between: (a number)"> and </mrk> Is it possible? thanks for your help. (4 Replies)
Discussion started by: louisJ
4 Replies

9. Shell Programming and Scripting

awk to replace a specific field in certain condition

Hi, I have a file like below PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Discussion started by: mady135
7 Replies

10. Shell Programming and Scripting

awk to assign points to variables based on conditions and update specific field

I have been reading old posts and trying to come up with a solution for the below: Use a tab-delimited input file to assign point to variables that are used to update a specific field, Rank. I really couldn't find too much in the way of assigning points to variable, but made an attempt at an awk... (4 Replies)
Discussion started by: cmccabe
4 Replies
CSV2LATEX(1)						      General Commands Manual						      CSV2LATEX(1)

NAME
csv2latex -- convert a csv file into a LaTeX document SYNOPSIS
csv2latex [--nohead] [--longtable] [--noescape] [--guess] [--separator c|s|t|p|l] [--block q|d|n] [--lines #] [--position l|c|r] [--colorrows 0-1] [--reduce 1|2|3|4] [--repeatheader] [--nohlines] [--novlines] [file] DESCRIPTION
This manual page documents the csv2latex program. csv2latex is a program that reads a "comma separated values" (csv) file and outputs a LaTeX file with one or more tabular environments to display the printable values of the csv file. The LaTeX code is flushed on the standard output. So-called "comma separated values" files are common formats for exchanging two-dimensinal tables between programs such as spreadsheets edi- tors, to represent almost any kind of data. By default, a csv file is made of printable data separated by commas (`,'), each comma repre- senting a `cell' separator, and each line representing a row. By extension, cell separators can be represented by tabs if the comma is con- sidered as printable data. Moreover, some non true csv files can be assumed as two-dimensional tables as well. In some circumstances, if the printable data includes the cell separator of the exchange format, the latter can use a second extra character to embrace the printable data into a block (e.g: quoted text). Thus, it is still possible to parse the file by using the block delimiter (used twice to embrace the cell) instead of the separator. csv2latex aims to parse various csv formats plus formats that fits into the above definiton, assuming the data is text, and to produce a yet simple LaTeX file using the "tabular" environment for a table-style layout. Some options of output will also use macros provided by extra LaTeX packages that are commonly included in the main LaTeX distributions. OPTIONS
This program follows the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -h --help Show summary of options. -v --version Show version of program. -n --nohead Do not output the LaTeX document header. This is useful when the output is to be included as a separate file into the master document. -t --longtable uses the 'longtable' package instead of the 'tabular' one. This is useful when the input is long, with --lines 0 option. This option uses the extra `longtable' LaTeX package. If you also use --nohead option, do not forget to add the following line into the header of your master document: "usepackage{longtable}". -x --noescape Do not escape TeX control characters from the input. This is useful when the input contains already TeX code. -g --guess Try to guess the csv format. This is useful when the input is not strictly a comma separated set of printable data. For exam- ple, a line like %Foo, Bar%:%Wizz: Hey% may be parsed as "Foo, Bar" then "Wizz: Hey". -s c|s|t|p|l --separator c|s|t|p|l Set the given separator as cell separator of the csv format. `c' means a comma (default). `s' means a semicolon. `t' means a tab. `p' means a space. `l' means a colon. -b q|d|n --block q|d|n Set the given block delimiter that embraces the printable data of the csv format. `q' means a simple quote. `d' means a double quote. `n' means no quoting at all (default). -l # --lines # Force to output multiple tabulars, each having a limited number of lines. The given argument must be a POSITIVE INTEGER VALUE. This is useful when the number of input rows is too big to fit into a single papersheet. A good average for a4 paper is about 40 lines (default). 0 means infinity (actualy about 2 Giga lines). -p l|c|r --position l|c|r Set the text position in all cells at once. This simply uses one of the three basic cell formating options of the LaTeX tabular environment. `l' means left-aligned (default). `c' means centered. `r' means right-aligned. -c 0-1 --colorrows 0-1 Alternate white/gray rows on the LaTeX output, having the given graylevel. The given argument must be a REAL NUMBER BETWEEN 0 AND 1. 0 means black while 1 means white. A nice looking value is 0.75 when printed on white paper. This option uses the extra `colortbl' LaTeX package. If you also use --nohead option, do not forget to add the following line into the header of your mas- ter document: "usepackage{colortbl}". -r 1|2|3|4 --reduce 1|2|3|4 Reduce the size of the tabular and the font in the LaTeX output, given a reduction level. The given argument must be one of 1, 2, 3 or 4. The more the level is high, the more the tabular will appear small. This is useful to shrink the table width when the printable data is made of very long text. This option uses the extra `relsize' LaTeX package. If you also use --nohead option, do not forget to add the following line into the header of your master document: "usepackage{relsize}". -z --nohlines Do not output horizontal lines in the table(s). -y --novlines Do not output vertical lines in the table(s). -e --repeatheader Repeat the first row of the first table in every table. This is useful when the output is very long and separated in multiple tables. EXAMPLES
Create a PDF document with small text, alternate gray rows, 80 lines per table, from a guessed csv format of the january stats that my boss created with his super point-and-click spreadsheet program (which could not generate a PDF output!). csv2latex --guess --lines 80 --colorrows 0.75 --reduce 2 january_stats.csv > january_stats.tex && pdflatex january_stats.tex Quickly preview a phonebook from a file formated as "Surname" "Name" "Phone" "Cellular": csv2latex -s p -b d -l 42 phonebook-sorted.txt | latex SEE ALSO
tex (1), latex (1). CSV2LATEX(1)
All times are GMT -4. The time now is 05:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy