11

How can I grep / awk this?

 3 years ago
source link: https://www.codesd.com/item/how-can-i-grep-awk-this.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How can I grep / awk this?

advertisements

I'm pretty new to Linux and I'm still learning the commands. All I want to do is format my .txt file.

Here is what my file looks like:

hello hello
goodbye goodbye
random random
example example
last last

All I want to do is remove the space and replace it with a semi-colon.

For example:

hello:hello
goodbye:goodbye
random:random
example:example
last:last

I'm not sure what command will accomplish this task, I'm pretty sure it's grep or awk. It would be great if someone can help me out on this. Thanks, all help is appreciated.


sed is the simplest tool for this task:

sed 's/ /:/' infile > outfile

Related Articles

How can I grep a word closer to a file?

How can i grep a nearer word from a file ? E.g 04-02-2010 Workingday 05-02-2010 Workingday 06-02-2010 Workingday 07-02-2010 Holiday 08-02-2010 Workingday 09-02-2010 Workingday I stored above data in a file 'feb2010', By this commend i stored date in

MySQL, how can I speed up this query that takes 1.4 seconds?

How can I speed up this query ? SELECT PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM Pads WHERE RemoveMeDate = '2001-01-01 00:00:00' ORDER BY VersionAddDate DESC

warnings () does not work in a function? How can we get around this?

op <- options(warn=0) #although doesn't work for any value of warn assign("last.warning", NULL, envir = baseenv()) thisDoesntWork<- function() { warning("HEY, this is definitely a warning!") cat(paste("number of warnings:&qu

How can I avoid getting this wrong MySQL column specifier for the COLUMN NAME column?

How can I avoid getting this MySQL error Incorrect column specifier for column topic_id ? MySQL Error... #1063 - Incorrect column specifier for column 'topic_id' SQL Schema... CREATE TABLE discussion_topics ( topic_id char(36) NOT NULL AUTO_INCREMENT

How can I use awk or grep to capture an entire Python traceback in a log file?

A log file contains a number of Python tracebacks. I only care about tracebacks raised because of a KevinCustomError. There may be more than one of this class of error in the file. How can I use grep, another popular unix command, or a combination th

How can I call Awk Print Variable in Expect Script that uses Spawn?

I've been creating some basic system health checks, and one of the checks includes a yum repo health status that uses one of Chef's tools called 'knife'. However, when I try to awk a column, I get can't read "4": no such variable. Here is what I

How can I grep in parallel?

I usually use grep -rIn pattern_str big_source_code_dir to find some thing. but the grep is not parallel, how do I make it parallel? My system has 4 cores, if the grep can use all the cores, it would be faster.There will not be speed improvement if y

How can I use awk to detect lines that have only one field and print it with the following line?

I've a file.txt written in this way (without the beginning dot, just number): 0 0.421915 0.420615 192000 0.420397 0.420802 192000 1 0.423915 0.423681 768000 0.421658 0.421474 768000 and I'd like to take the line with only one column and the following

How can I ensure that this method closes the outputtream?

How can I make sure that this method closes the OutputStream so a memory-leak won't happen? public static void store(Properties properties, Class script) throws IOException { ScriptManifest scriptManifest = (ScriptManifest) script.getAnnotation(Scrip

How can I de-serialize this json with C #?

With C#, I try without success to de-serialize this json content : { "code":200, "message":"OK", "name":"The name", "description":"The description", "tags":{ "0.1.3"

How can I further dry this Rails Controller action?

Our application uses a number of environments so we can experiment with settings without breaking things. In a typical controller action, I have something like this: def some_action ... if @foo.development_mode == 'Production' @settings = SomeHelper:

How can I listen when this Java application is resized?

I have this basic Java application in witch dim_x and dim_y represent the dimensions of the window and the canvas within it. How can I get these values to change as the user changes the size of the window so that what is drawn on the canvas shrinks/e

How can Zend Framework use $ this out of a class?

I am fairly new to OOP in PHP, and I tried to create my own layout class. In my case, it works like this: $layout = new Layout('some name'); // title $layout->setStyle('somestyle.css'); $layout->addDiv('id/class', $content ); Then, just in order to

How can I properly center this div in its container? What's wrong?

I am not so into HTML and CSS and I have some problems trying to center a div into it's container that I have into a very old legaxy JSP page. So the situation is the following, I have something like this: <div class="panel-wrapper"> <d

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK