General :: Use Awk To Matching In Only A Specific Column?
Jul 12, 2010
Im trying to use awk to do matching in only a specific column
example.txt:
www.google.com www.example.com
www.google.com/search www.example2.com
i used:
awk '{ (if $1 == "http://www.google.com") print $2}' example.txt
this awk statement only returns the first line, and i cant seems to make it perform in a way to match based on keywords like GREP. Is there any way to make display the other lines which contains "google" also?
View 1 Replies
ADVERTISEMENT
Mar 8, 2010
shell commands for such two goals?
In a tab-delimited file,
Code:
1aIa11aa
2bIIa22aa
1cIIIaabcaa
4dIVaabcaa
1. How can I find the non-unique values in the 1st column (1, in this case)?
2. How can I find the non-integer values in the 5th column (abc, in this case)?
View 3 Replies
View Related
Apr 24, 2010
Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.
[code]....
My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:
[code]....
Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.
[code]....
how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?
View 10 Replies
View Related
May 1, 2010
Trying to change to upper case first letter of every word over a specific column.
View 10 Replies
View Related
Jul 19, 2010
How would i calculate following values.Initial file
10 3
20 4
How would i calculate 3rd column which should be addition of value in 1 and 2nd column.File after calculation
10 3 13
20 4 24
View 14 Replies
View Related
Mar 7, 2010
i use this script to get the time and date of back and fourth transactions for a particular execution id. I use a substr command on the 5th column to to cut the milli seconds off the time value. - otherwise the times would look like 08:30:04.235
grep <executionID> <auditfile> | awk '{ print $1, $2, $3, $4, substr($5,1,8}
FIX -> Mon 3/1/2010 08:30:04
FIX <- Mon 3/1/2010 08:32:36
FIX <- Mon 3/1/2010 08:35:08
[code].....
anyhow - i append two sed commands to further clarify the direction of the message.
awk '{ print $1, $2, $3, $4, substr($5,1,8} | sed -e 's/->/ ->IN/g' | sed -e 's/<-/<-OUT/g'
FIX -> IN Mon 3/1/2010 08:30:04
FIX <- OUT Mon 3/1/2010 08:32:36
[code]....
I tried using an awk gsub () command within the string instead of the two seds, but it did not work:
awk '{ print gsub(/<regex>/, <replace with>,$1), $2, $3, $4, substr($5,1,8}
the sed works ok, but it would be cooler to make the replacement within the awk command:
gsub(/->/,-> IN, $1)
Is there a way where i could replace the value of the $1 column in the awk print string?
View 1 Replies
View Related
Mar 2, 2011
I have two table files with x (1st column) ,y (2nd column) coordinates and intensity (3rd column). I need to match these two tables and divide the intensities at the consecutive coordinates on the 3rd column. The problem is the size of the tables are not same and I want to ignore the lines if they are not in one of the other file.
Here is Table 1:
Code:
-7.500-30.00013.006
-7.500-22.50037.952
-7.500-15.00060.962
-7.500-7.50040.922
-7.5000.00014.348
code....
View 3 Replies
View Related
Jul 15, 2010
I have a multicolumn datas, like
a1 b1 ... f1
a2 b2 ... f2
. . ... .
[code]...
I would like to make a file with all these data in one column, like
a1
a2
.
.
[code]....
Can it be done with awk or some other command? Also, is it possible then do add another column in front of this one with numbers of the lines (for every previous column), like
1 a1
2 a2
. .
. .
[code].....
View 14 Replies
View Related
Dec 2, 2010
for example
else {
for fileDOC in $location/*.doc
do
[code]...
View 12 Replies
View Related
Mar 13, 2011
I have a requirement to list files using find command My folder contains below list of files with out extention.I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.
View 7 Replies
View Related
Feb 22, 2010
How can I remove all .swp files in all of my subdirectories under Linux?
View 4 Replies
View Related
May 19, 2010
I am running Linux and I have some basic console knowledge but my current problem is quite difficult and I dont know how to achieve this. I want/need to rename everything within a folder that matches a given string.
By everything I mean:
folders/files
content within a file
content in hidden files
Basically I want to refactor a Java-project. Sure, I could use Eclipse to handle the replacing, but this leaves out the folders or resources outside of my workspace. I was thinking of a script that could do the job for me but this seems rather tricky. For instance when it comes to folder-/file-rename I want to replace only the part of the name that matches my string, the rest should remain untouched.
View 2 Replies
View Related
Jul 19, 2011
If I wanted to copy all *.so files from src to dst I'd do:
cp src/*.so dst
However, I want to copy all *.so files from src and it's subdirs into dst.
View 2 Replies
View Related
Jul 7, 2011
How can I use grep -Ev "pattern" not only to delete the matching "pattern" but to edit and save the file permanently as well
View 2 Replies
View Related
Oct 18, 2009
I'm trying to do something very basic in bash. It's a kind of cross-reference matching between 2 files. I have a file1.txt. It's like this:
Code:
item1
item3
item4
...
I Have a file2.txt. It's like this:
Code:
item1 "Properties of item1"
item2 "Properties of item2"
item3 "Properties of item3"
item4 "Properties of item4"
item5 "Properties of item5"
...
My goal is to print out the lines in file2 that contains lines present in file1. I do:
Code:
for i in $(cat file1.txt); do grep $i file2.txt; done but I get no output. Will someone please tell me where am I mistaking?
View 3 Replies
View Related
Feb 1, 2011
I had debian squeeze already installed, then installed win 7. Windows overwrote by MBR, as I expected it to, so I used an ubuntu live cd to reinstall grub2 to debian root.
I rebooted, and sure enough I had grub back. The boot menu has debian on it. Just debian (crunchbang actually, but its the same thing).
So I added a script in /etc/grub.d (called Windows_11) to create a windows chainloader entry in grub.cfg, and ran update-grub.
Update-grub picks up my /etc/grub.d/Windows_11 script, and adds an appropriate chainloader entry to /boot/grub/grub.cfg.
So I would expect this new chainloader entry to show up in my boot menu when I boot up. But it doesn't; on booting I only have the option to select debian.
Here is my /boot/grub/grub.cfg -
Code:
### BEGIN /etc/grub.d/10_linux ###
menuentry 'CrunchBang Linux, with Linux 2.6.32-5-686' --class crunchbang --class gnu-linux --class gnu --class os {
insmod part_msdos
[Code].....
View 11 Replies
View Related
Apr 8, 2011
I tried to remove a folder in linux, davidanderson'spetshop_617 as a folder name. It contained a single quotes. By using the following command
rm -r path/davidanderson'spetshop_617
I am getting this error ,Error: unexpected EOF while looking for matching `''unexpected end of files.How can i remove the folder?
View 2 Replies
View Related
May 4, 2011
I have a file with joker character patterns:
./include/*
./src/*
etc.
From the current directory I would like to recursively get the list of files that do not match these patterns.
View 2 Replies
View Related
Sep 9, 2011
I've got files in a directory as follows:
1.png
1_thumb.png
1-1.png
1-1_thumb.png
[code]....
I want to list all the files that don't have a copy with the same filename with -1 somewhere in it. So, in the example above, the results would be 3.png.
NB: the file and its copy with "-1" in it will be the same filesize, if that helps.
View 2 Replies
View Related
Feb 11, 2011
I have 2 massive duplicate dirs of the same format as below:
dir1
subdir1
file1
subdir2
file1
subdir3
file1
...
Dir2 is the same, but it has some newer files of the same name. I want to copy all file1's from Dir2 to the same name and folders in dir1. So basically something like:
cp -pr bkpDir1/*/*-big.gif Dir2/*/*-big.gif
This works for singular cases:
cp -pr bkpDir1/uniquesubdir/*-big.gif Dir2/uniquesubdir/*-big.gif
But not for wildcards:
cp -pr bkpDir1/subdir*/*-big.gif Dir2/subdir*/*-big.gif
Anyway the aim is to do the first cp above, I have tried a few options using find. In trying to show an example stumbled upon a way that worked, while in dir2:
find */*-big.gif | xargs -i cp -rp {} ../dir1/{}
Sure there are better ways also...
View 1 Replies
View Related
Apr 16, 2010
I am writing a shell script that finds all files named <myFile> in a directory <dir> or any of its subdirectories, recursively. I also need to take care of symbolic links that may form cycles, to avoid infinite loops. I am not supposed to use find command for the same
I started writing the code but got stuck. I thought using recursion may be a smart way, but its not working.
Code:
#!/bin/sh
findFiles()
{
thisDIR=$1
#cd $thisDIR
code....
View 5 Replies
View Related
Jan 18, 2011
I have a two column file and I need to create a new column in between the first and second but the new column adds a value to the first. E.g.code...
I thought I had figured out how to do it with the following but it just hangs:
awk -F '{print $0,$0+25,$1}' file_in > file_out
Also tried the following to no avail:
awk -F,-v OFS,'{print $0,$0+25,$1}' file_in > file_out
I can add the new column with the added value to the last column easy ( awk '{print $0,$0+25}' file_in > file_out).
View 8 Replies
View Related
Apr 3, 2010
I'm searching within Java files for some occurrence of a phrase:
find . -name '*.java' | xargs grep -l 'string'
How do I change this command to print to the shell all of the lines which contain a match?
View 4 Replies
View Related
Jul 22, 2010
What is the best and simplest way to compare two directory structures without actually comparing the data in files. This works fine:
diff -qr dir1 dir2
But it's really slow because it's comparing files too. Is there a switch for diff or another simple cli tool to do this?
View 4 Replies
View Related
Sep 13, 2011
I have many files in a folder for example
Kiran.txt
Kiran1.txt
Kiran221.txt
Kiran144.txt
Time.csv
[Code]...
From this directory, I want to know how I could use grep to display files based on part of their filename - for example those starting with "Account" or those ending in ".sh".
View 4 Replies
View Related
Feb 23, 2011
I have not defined a user vimrc, OS is redhat 4.6 and after a search and replace the first column in the editor is highlighted yellow and it stays that way as I close and open vim. This is the /etc/vimrc that came on the system. anyone see a bug or a reason it would do that?
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
[Code]....
View 2 Replies
View Related
Oct 20, 2010
1. when we run od command it displays octal values. But the first column will be always 000000. after that the actual file contents are displayed. Can anyone tell the meaning of that.
2. When we run ls -l command, in the first line of the output, we can see some integer value. What is the significance of that value.
View 4 Replies
View Related
Apr 26, 2010
I have some series of files, which actually named bellow
<day_month_yr>_<hh:mm:ss>.<host_name>.<IP.ip.ip.ip>.<log_name>.txt
I want to show this file name below the column may be
Date Time Host_Name IP_address Login_Name
----- ---- --------- ---------- ----------
<day_month_yr> <hh:mm:ss> host_name x.x.x.x log_name
...
View 5 Replies
View Related
Feb 22, 2010
It is very important for my research work. For example mydata.txt:
id type x y z
1 6 0.474611 0.227223 0.583947
2 4 0.422894 0.22726 0.536791
3 5 0.448963 0.200148 0.560336
4 3 0.386478 0.207721 0.515293
5 6 0.371617 0.22361 0.582206
6 4 0.32123 0.222999 0.534782
How to change second column (type) whose values are 4 and 3 to value 1, so that mydata.text file become:
id type x y z
1 6 0.474611 0.227223 0.583947
2 1 0.422894 0.22726 0.536791
3 5 0.448963 0.200148 0.560336
4 1 0.386478 0.207721 0.515293
5 6 0.371617 0.22361 0.582206
6 1 0.32123 0.222999 0.534782
View 6 Replies
View Related
May 20, 2011
I have a basic question of awk.
Code:
var=/test/build/create/sls
echo $var | awk '{ FS = ":" ; print $NF }'
/test/build/create/sls
I am trying to extract last column from the above awk one liner.
View 4 Replies
View Related