Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Next
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
Twitch
YouTube
Facebook (EN Publishing)
Facebook (EN World)
Twitter
Instagram
TikTok
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Community
General Tabletop Discussion
*Geek Talk & Media
Anyone still using 'sed'? I need guidance
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="azhrei_fje" data-source="post: 2951014" data-attributes="member: 12966"><p>Does it <u>have</u> to be <strong>sed</strong>? The reason I ask is that there is no way to guarantee that you're changing the 4th field.</p><p></p><p>For example, the following command (run at the shell prompt):</p><p></p><p>[CODE]sed -e 's:old value:new value:' < input > output[/CODE]</p><p>Would read <em>input</em> and change any occurrence of 'old value' with 'new value'. But there's no way to specifically check for field 4.</p><p></p><p>Since you're going to be running this on Fedora, I would suggest using either <strong>awk</strong> or <strong>perl</strong> instead. They can count the fields for you and you can be sure of replacing just a particular field.</p><p></p><p>For example, to change 'old value' to 'new value' <u>only in field 4</u>, use one of the following:</p><p></p><p>[CODE]awk F='|' '$4 == "old value" { $4 = "new value"; print }' < input > output[/CODE]</p><p>or</p><p></p><p>[CODE]perl -pe 'split("|"); $F[3] =~ s:old value:new value:; print join("|", @F);' < input > output[/CODE]</p><p>If you want to put those into files and make them scripts, use these:</p><p></p><p>[CODE]#!/usr/bin/awk -f</p><p>BEGIN { FS = "|" }</p><p>$4 == "old value" { $4 = "new value"; print }[/CODE]</p><p>or</p><p></p><p>[CODE]#!/usr/bin/perl</p><p>while (<>) {</p><p> split("|");</p><p> $F[3] =~ s:old value:old value:;</p><p> print join("|", @F);</p><p>}[/CODE]</p><p>After making the files executable, you can just run them and redirect the input and output (or use this in pipes or whatever, just like with <strong>grep</strong>, for example):</p><p></p><p>[CODE]awkscript < input > output[/CODE]</p><p>or</p><p></p><p>[CODE]perlscript < input > output[/CODE]</p><p>Good luck! You can PM me if you want more details. (I teach a bunch of Unix/Linux classes, including shell scripting and various programming classes. I'd be glad to help.)</p></blockquote><p></p>
[QUOTE="azhrei_fje, post: 2951014, member: 12966"] Does it [u]have[/u] to be [b]sed[/b]? The reason I ask is that there is no way to guarantee that you're changing the 4th field. For example, the following command (run at the shell prompt): [CODE]sed -e 's:old value:new value:' < input > output[/CODE] Would read [i]input[/i] and change any occurrence of 'old value' with 'new value'. But there's no way to specifically check for field 4. Since you're going to be running this on Fedora, I would suggest using either [b]awk[/b] or [b]perl[/b] instead. They can count the fields for you and you can be sure of replacing just a particular field. For example, to change 'old value' to 'new value' [u]only in field 4[/u], use one of the following: [CODE]awk F='|' '$4 == "old value" { $4 = "new value"; print }' < input > output[/CODE] or [CODE]perl -pe 'split("|"); $F[3] =~ s:old value:new value:; print join("|", @F);' < input > output[/CODE] If you want to put those into files and make them scripts, use these: [CODE]#!/usr/bin/awk -f BEGIN { FS = "|" } $4 == "old value" { $4 = "new value"; print }[/CODE] or [CODE]#!/usr/bin/perl while (<>) { split("|"); $F[3] =~ s:old value:old value:; print join("|", @F); }[/CODE] After making the files executable, you can just run them and redirect the input and output (or use this in pipes or whatever, just like with [b]grep[/b], for example): [CODE]awkscript < input > output[/CODE] or [CODE]perlscript < input > output[/CODE] Good luck! You can PM me if you want more details. (I teach a bunch of Unix/Linux classes, including shell scripting and various programming classes. I'd be glad to help.) [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Geek Talk & Media
Anyone still using 'sed'? I need guidance
Top