Programming :: Awk: Swap Fields Given A Condition?
Oct 8, 2010
I have a file records as follows:
Jane pepe@pepe.biz
john@pepe.net John
Joe joe@willxyz.org
How can I get that always first field be given name and second one be the mail address?
I've tried
Code:
awk '$1 ~ /@/ { a=$1 ; $1=$2; $2=a; print }' file
But that doesn't worked
View 5 Replies
ADVERTISEMENT
Jun 29, 2010
I just started with Pthreads and don't really know much about it. I want to suspend pthreads but apparently, there is no such function as pthread_suspend. but I don't understand why we need both mutex and condition to suspend and resume a pthread. Is it possible to suspend and resume it without using conditions?
View 1 Replies
View Related
Apr 28, 2010
i have a question regarding the use of a statement, like following, in a iptables script.
Code:
BLOCKMAC="/root/mac.blocked"
MACS=$(grep -Ev "^#" $BLOCKMAC)
[code]...
View 2 Replies
View Related
Jun 18, 2010
i have a host file called myhosts.txt as follow:
Quote:
10.20.3.9 host1
10.20.3.10 host2
10.20.3.11 host3
[code]...
In my script, i am using NSLOOKUP to get the ip address of a host that just rebooted and connected to my network (this part has been done).But now i want to check the myhosts.txt file if the host has the same or different IP address, if is different then myhosts.txt file must be updated with the new IP.i am using the following AWk command:
Quote:
awk '/host4/{$1=val}{print}' val=10.0.3.4 /tmp/myhosts.txt
it prints on screen fine and i see the host4's ip address gets replaced but the actual file does not get updated with the new IP. I might need to use gsub?
View 11 Replies
View Related
Apr 27, 2010
Let say I would like to check /etc/profile whether defined umask 022
umaskcheck=$(What to defined here?)
if [ What to define here? ]
then
[code]....
View 2 Replies
View Related
Apr 27, 2010
I have a filename file-name-here-1.2.3-i486-2.tar I would like to know how to remove the last two fields leaving only: file-name-here-1.2.3
I can use:
x=file-name-here-1.2.3-i486-2.tar
echo ${a%-*}
to remove the last field (after -) but how do i remove the last two in one fell swoop?
View 2 Replies
View Related
Mar 8, 2011
need to modify some scripts to repeat the commands in them until a variable returns a proper value. I need it to add some redundancy to some scripts i use to upload files to a remote server.This is an example of a portion of those scripts:
Code:
################## site UPLOAD ##################
site_login=$(curl -c $site_cookie -L -F user=$site_user -F pass=$site_password -F
[code]....
View 4 Replies
View Related
Sep 17, 2009
I'm trying to implement an assert function similar to:[url]
However, I'm having trouble with file existence testing when the file name has a space in it.
I have distilled the problem down to the following:
This code works as expected, printing 'yes' if '~/test file' exists, and no if not.
Code:
However, this code gives an error.
Code:
The error:
Code:
Which tells me that it is splitting ["~/test file"] into ["~/test] and [file"]. Why? Is there a way around this?
Note that if you simply use a file path without a space, both cases work perfectly. Is this a BASH bug possibly? I just can't understand why the first would work, but the second wouldn't.
View 8 Replies
View Related
Mar 3, 2010
I have a csv file like, having HDR segment and multiple LIN01 segment in each line:like
Here i want to split file in two, one having LIN01 segment which have LR at end, and one which have LF at end in LIN01 segment.
Is it possible to created awk or shell script for this?
View 3 Replies
View Related
May 31, 2010
I want to extract all the common entries in the given 3 columns(fields) in the file using awk::can somebody tell me how it can be done in awk...the file is::
NC_000858.pttNC_000858.fnaNC_001403.rnt
NC_001362.pttNC_001436.fnaNC_001407.rnt
NC_001364.pttNC_001503.fnaNC_001488.rnt
[code]....
View 8 Replies
View Related
Jul 16, 2011
Dear expertsI have files like
ABD : 5869 events, relative ratio : 1.173800E-01 , sum of ratios : 1.173800E-01
VBD : 12147 events, relative ratio : 2.429400E-01 , sum of ratios : 3.603200E-01
SDF : 17000 events, relative ratio : 3.400000E-01 , sum of ratios : 7.003200E-01
[code]....
View 3 Replies
View Related
Mar 2, 2011
I have a file with 200 000 lines and I want to append the fields of each line based on matching first field. The resulting file should have 70 000 columns but has "only" 18 000. The command I'm using is working perfectly with a smaller file, wich lead to 14 000 columns. Could there be a limit in number of fields that awk can handle ? Here's my awk command :
Code:
awk -F, 'END { for (k in _) print _[k] } { _[$1] = $1 in _ ? _[$1] FS $4 : $1","$4 } ' file > out
Also, this command writes ^M (windows line break) after each columns. Removing them is easy but where do they come from ? Working on Ubuntu 10.10
View 4 Replies
View Related
Dec 16, 2010
I have an array called @logons. How can I step thru the array and split the fields? This is what I have so far, but doesnt work. I got the feeling I the split statement syntax is incorrect.
Code:
print @logons;
foreach my $logons(@logons){
($userid, $ip) = split(',',$logons);
[code]....
Update: Appears the data in @logons has a column header from the mysql query which I used to populate it with. So that code which I was testing does indeed work.
View 10 Replies
View Related
Apr 9, 2009
I want to write a function which calculates the space needed between fields, to generate a table with aligned fields, like when you type "ls -l", the operating system generates a table with beautifully aligned fields. I've got this code so far:
Code:
for line in $(cat tmpSearch)
do
line=`echo $line | tr ":" " "`
[code]....
View 2 Replies
View Related
Mar 25, 2010
i am reading a database flat file with the "awk" command which has 4 fields separated by colon ":" .I want to show the output of these fields in a certain way that every record is numbered e.g
1.some text
2.some text
Is there a way to do this?
View 14 Replies
View Related
Apr 15, 2009
constructing a protocol where in it involves sending and receiving different files, so sending data over consists of file name, size of the file and content of the file, so while receiving can i use functions like strchr() to differentiate these fields for sockets? so to allocate memory for file to save i need to have its size.
View 3 Replies
View Related
Mar 14, 2010
I am faced with the following problem; I need to update all fields of type datetime without ... with the following sort data:01-01-2010 12:10:30.256 - this is just an example.these fields are restricted with a unique constrained. My question is how can I generate the above sort data, especially the last three numbers with leading point. After that how can I update a table with existing data with this newly generated data so that the fields really do carry unique data.As you probably can read out of my question, I read through the help in pgAdmin and came as far as generating date, maybe datetime but not the .123 number. And a little insert script I found in the help, that I modified as UPDATE resulted in updating only the last generated data in all required fields.
View 7 Replies
View Related
Feb 9, 2011
I want to display the contents of a particular log file (simple text file, I mean in Linux). But there is a problem: The contents need to be organized in a fixed format. Have a look at this log file:
sampleLog.txt
Code:
User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!
[code]....
So, while displaying the contents of above file on a web page, I want to format the field names found in the log file: User Name:, Reported Problems Description:, and Remarks:. These fields may contain a variable length of text and no specific line number is assumed for them to appear on.
The desired output should look like this:
User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!
[code]....
Well, what I am trying to do may sound wierd to some of you. The filed "Reported Problems Description:" can possible contain text which embeds colon (.
View 15 Replies
View Related
Mar 28, 2011
Is it possible to swap a client ip and port ? This is what I am trying to do. Let say you have Comp1 and Comp2 And you have Server between them. My goal is to get Comp1 and Comp2 know each others IP So Comp1 connects to server And server stores comp1's IP In a text file or other place And Comp2 connect to server And server also stores his info And then both comp1 and comp2 dowload the tex file And use the info on it.
View 9 Replies
View Related
Mar 20, 2011
Does one need to Check the Swap filesystem, from time to time
View 4 Replies
View Related
Dec 7, 2010
Lucid on an Acer Travelmate800.Can anyone tell me why I have 0k for swap space? I allocated swap which I can see in my Disk Utility's 'volumes' display.
View 5 Replies
View Related
Aug 16, 2010
RAM for older machines like I use is fairly cheap these days. But flash memory is just as cheap or cheaper. So I'd like to ask about the feasibility of expanding my system's memory using flash memory. And about whether creating a partition for swap on the flash memory, or whether a swap file on the flash device, is the better way to go.
By flash memory I have in mind mainly USB sticks or what are sometimes called "pen drives." But I do also have CF and SD cards that, with the proper cheap adapter (one of which I already own for adapting CF) could be used to create extra swap space. So, what is the current consensus on the feasibility/advisability of using flash memory for swap? I've read about the limited write cycles of flash being an argument against using it for swap. But recent reading indicates to me that the limited write cycles problem applies mostly to older, smaller-capacity flash memory. Some will come out and say that, for larger-capacity flash memory, the life of the device is likely to exceed the amount of time your current computer will be useful (I think I've seen estimates in the range of 3-4 years life--minimum--for newer, higher-capacity flash memory).
A more persuasive argument I've heard against using flash memory for swap is that access times for these devices can be much slower than SATA, and maybe even IDE, hard drives. That would certainly dictate against using flash memory for swap.
So, how about some input on this issue? Anyone using flash memory for swap? If so, what kind (e.g., usb stick or SD/CF)? Are you using a swap file or a swap partition? How's system performance? Likewise, has anyone had flash-memory-used-as-swap die on them? The consequences would undoubtedly be dire. Also, has anyone measured flash memory access times to confirm or refute claims about slow access times? Are some types of flash memory better/worse than others in terms of access times?
View 2 Replies
View Related
Mar 18, 2010
I need to write an else-if condition in a makefile, and though the format is posted on several websites, nothing seem to be working, andI get an error everytime. Could anybody please write a small example with an else-if conditional in a maekefile?
View 1 Replies
View Related
Jun 19, 2011
When I used windows, I used to perform following operations on regular basis:
1) disk cleanup
2) disk defragmentation
3) virus/spyware/malware check
4) deleting temp files left by deleted files
5) and many more.......
Does Linux system needs that to be done too? What should be done to maintain Linux in fast & furious condition....as it is now.....
View 10 Replies
View Related
Aug 13, 2010
Is there some way to filter output of command by OR condition in Linux? There is filtering by AND condition with grep in way like:
ls -l | grep "^a" | grep "z$"
That says: list all files that beggins with "a" AND ends with "z" (so there is shorter way to write this: grep "^a.*z$", but it is not matter). Is there some way to perform test by OR condition? For example: files that starts exactly with "xen" OR files that ends exactly with ".rpm". But exactly, not something like:
grep "[xen]{0,3}.*[.rpm]{0,4}"
View 2 Replies
View Related
Mar 13, 2011
I have the following folder structure:
parent
- folder1
- main1.x
- main1.y
[Code].....
So, how can I achieve this?
View 2 Replies
View Related
May 2, 2011
How can I have ELSE condition in procmailrc I mean if the mail was from X and Subject has Y OR .... DO something ELSE DO SOMETHING ELSE. I do not want to use two different conditions for each state I want use just one condition and its ELSE because putting too recipes in procmailrc make it too slow .
View 2 Replies
View Related
Feb 19, 2010
I know it's possible, but does anyone have a URL or tutorial on how to do this?
View 3 Replies
View Related
May 28, 2011
I am writing a simple shell script where it checks the condition using if condition.
Code:
if [ $name == "JOHN" ] then admin='YES'; fi
if I use like this I am getting below error
[code]....
View 1 Replies
View Related
Jan 16, 2011
First of all, This is my first post in the forums, so - Hello all, nice to meet you. This is my first time with Ubuntu, and so, ran into a lot of problems. This problem is in installing counter strike. I know that there are a lot of guides and FAQ's online that give you lots of help on that, but I ran into an unique problem.
I installed the non-steam version of Counter Strike ( using wine ofcourse ). It created a shortcut in my desktop and I launch the counter strike game. I enter my cd key and then I select a profile, select a map, select the bots and then, it starts loading. After that, it stops half way and then it quits.
View 1 Replies
View Related